| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/escape.h" | 5 #include "net/base/escape.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 240 |
| 241 // Everything except alphanumerics, the reserved characters(;/?:@&=+$,) and | 241 // Everything except alphanumerics, the reserved characters(;/?:@&=+$,) and |
| 242 // !'()*-._~% | 242 // !'()*-._~% |
| 243 static const Charmap kExternalHandlerCharmap = {{ | 243 static const Charmap kExternalHandlerCharmap = {{ |
| 244 0xffffffffL, 0x5000080dL, 0x68000000L, 0xb8000001L, | 244 0xffffffffL, 0x5000080dL, 0x68000000L, 0xb8000001L, |
| 245 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL | 245 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL |
| 246 }}; | 246 }}; |
| 247 | 247 |
| 248 } // namespace | 248 } // namespace |
| 249 | 249 |
| 250 std::string EscapeQueryParamValue(const std::string& text, bool use_plus) { |
| 251 return Escape(text, kQueryCharmap, use_plus); |
| 252 } |
| 253 |
| 250 std::string EscapePath(const std::string& path) { | 254 std::string EscapePath(const std::string& path) { |
| 251 return Escape(path, kPathCharmap, false); | 255 return Escape(path, kPathCharmap, false); |
| 252 } | 256 } |
| 253 | 257 |
| 254 std::string EscapeUrlEncodedData(const std::string& path, bool use_plus) { | 258 std::string EscapeUrlEncodedData(const std::string& path, bool use_plus) { |
| 255 return Escape(path, kUrlEscape, use_plus); | 259 return Escape(path, kUrlEscape, use_plus); |
| 256 } | 260 } |
| 257 | 261 |
| 258 std::string EscapeNonASCII(const std::string& input) { | 262 std::string EscapeNonASCII(const std::string& input) { |
| 259 return Escape(input, kNonASCIICharmap, false); | 263 return Escape(input, kNonASCIICharmap, false); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 text.replace(iter, iter + ampersand_chars[i].length(), | 351 text.replace(iter, iter + ampersand_chars[i].length(), |
| 348 1, kEscapeToChars[i].replacement); | 352 1, kEscapeToChars[i].replacement); |
| 349 break; | 353 break; |
| 350 } | 354 } |
| 351 } | 355 } |
| 352 } | 356 } |
| 353 } | 357 } |
| 354 return text; | 358 return text; |
| 355 } | 359 } |
| 356 | 360 |
| 357 std::string EscapeQueryParamValue(const std::string& text, bool use_plus) { | |
| 358 return Escape(text, kQueryCharmap, use_plus); | |
| 359 } | |
| 360 | |
| 361 // Convert the string to a sequence of bytes and then % escape anything | |
| 362 // except alphanumerics and !'()*-._~ | |
| 363 string16 EscapeQueryParamValueUTF8(const string16& text, bool use_plus) { | |
| 364 return UTF8ToUTF16(Escape(UTF16ToUTF8(text), kQueryCharmap, use_plus)); | |
| 365 } | |
| 366 | |
| 367 namespace internal { | 361 namespace internal { |
| 368 | 362 |
| 369 AdjustEncodingOffset::AdjustEncodingOffset(const Adjustments& adjustments) | 363 AdjustEncodingOffset::AdjustEncodingOffset(const Adjustments& adjustments) |
| 370 : adjustments(adjustments) {} | 364 : adjustments(adjustments) {} |
| 371 | 365 |
| 372 void AdjustEncodingOffset::operator()(size_t& offset) { | 366 void AdjustEncodingOffset::operator()(size_t& offset) { |
| 373 // For each encoded character occurring before an offset subtract 2. | 367 // For each encoded character occurring before an offset subtract 2. |
| 374 if (offset == string16::npos) | 368 if (offset == string16::npos) |
| 375 return; | 369 return; |
| 376 size_t adjusted_offset = offset; | 370 size_t adjusted_offset = offset; |
| 377 for (Adjustments::const_iterator i = adjustments.begin(); | 371 for (Adjustments::const_iterator i = adjustments.begin(); |
| 378 i != adjustments.end(); ++i) { | 372 i != adjustments.end(); ++i) { |
| 379 size_t location = *i; | 373 size_t location = *i; |
| 380 if (offset <= location) { | 374 if (offset <= location) { |
| 381 offset = adjusted_offset; | 375 offset = adjusted_offset; |
| 382 return; | 376 return; |
| 383 } | 377 } |
| 384 if (offset <= (location + 2)) { | 378 if (offset <= (location + 2)) { |
| 385 offset = string16::npos; | 379 offset = string16::npos; |
| 386 return; | 380 return; |
| 387 } | 381 } |
| 388 adjusted_offset -= 2; | 382 adjusted_offset -= 2; |
| 389 } | 383 } |
| 390 offset = adjusted_offset; | 384 offset = adjusted_offset; |
| 391 } | 385 } |
| 392 | 386 |
| 393 } // namespace internal | 387 } // namespace internal |
| 394 | 388 |
| 395 } // namespace net | 389 } // namespace net |
| OLD | NEW |