| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "net/base/escape.h" | 7 #include "net/base/escape.h" |
| 8 | 8 |
| 9 #include "base/i18n/icu_string_conversions.h" | 9 #include "base/i18n/icu_string_conversions.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 // Everything except alphanumerics and !'()*-._~ | 183 // Everything except alphanumerics and !'()*-._~ |
| 184 // See RFC 2396 for the list of reserved characters. | 184 // See RFC 2396 for the list of reserved characters. |
| 185 static const Charmap kQueryCharmap( | 185 static const Charmap kQueryCharmap( |
| 186 0xffffffffL, 0xfc00987dL, 0x78000001L, 0xb8000001L, | 186 0xffffffffL, 0xfc00987dL, 0x78000001L, 0xb8000001L, |
| 187 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL); | 187 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL); |
| 188 | 188 |
| 189 std::string EscapeQueryParamValue(const std::string& text, bool use_plus) { | 189 std::string EscapeQueryParamValue(const std::string& text, bool use_plus) { |
| 190 return Escape(text, kQueryCharmap, use_plus); | 190 return Escape(text, kQueryCharmap, use_plus); |
| 191 } | 191 } |
| 192 | 192 |
| 193 std::string EscapeQueryParamValue(const std::string& text) { | |
| 194 return Escape(text, kQueryCharmap, true); | |
| 195 } | |
| 196 | |
| 197 // Convert the string to a sequence of bytes and then % escape anything | 193 // Convert the string to a sequence of bytes and then % escape anything |
| 198 // except alphanumerics and !'()*-._~ | 194 // except alphanumerics and !'()*-._~ |
| 199 std::wstring EscapeQueryParamValueUTF8(const std::wstring& text) { | 195 std::wstring EscapeQueryParamValueUTF8(const std::wstring& text, |
| 200 return UTF8ToWide(Escape(WideToUTF8(text), kQueryCharmap, true)); | 196 bool use_plus) { |
| 197 return UTF8ToWide(Escape(WideToUTF8(text), kQueryCharmap, use_plus)); |
| 201 } | 198 } |
| 202 | 199 |
| 203 // non-printable, non-7bit, and (including space) "#%:<>?[\]^`{|} | 200 // non-printable, non-7bit, and (including space) "#%:<>?[\]^`{|} |
| 204 static const Charmap kPathCharmap( | 201 static const Charmap kPathCharmap( |
| 205 0xffffffffL, 0xd400002dL, 0x78000000L, 0xb8000001L, | 202 0xffffffffL, 0xd400002dL, 0x78000000L, 0xb8000001L, |
| 206 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL); | 203 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL); |
| 207 | 204 |
| 208 std::string EscapePath(const std::string& path) { | 205 std::string EscapePath(const std::string& path) { |
| 209 return Escape(path, kPathCharmap, false); | 206 return Escape(path, kPathCharmap, false); |
| 210 } | 207 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 232 // !'()*-._~% | 229 // !'()*-._~% |
| 233 static const Charmap kExternalHandlerCharmap( | 230 static const Charmap kExternalHandlerCharmap( |
| 234 0xffffffffL, 0x5000080dL, 0x68000000L, 0xb8000001L, | 231 0xffffffffL, 0x5000080dL, 0x68000000L, 0xb8000001L, |
| 235 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL); | 232 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL); |
| 236 | 233 |
| 237 std::string EscapeExternalHandlerValue(const std::string& text) { | 234 std::string EscapeExternalHandlerValue(const std::string& text) { |
| 238 return Escape(text, kExternalHandlerCharmap, false); | 235 return Escape(text, kExternalHandlerCharmap, false); |
| 239 } | 236 } |
| 240 | 237 |
| 241 bool EscapeQueryParamValue(const string16& text, const char* codepage, | 238 bool EscapeQueryParamValue(const string16& text, const char* codepage, |
| 242 string16* escaped) { | 239 bool use_plus, string16* escaped) { |
| 243 // TODO(brettw) bug 1201094: this function should be removed, this "SKIP" | 240 // TODO(brettw) bug 1201094: this function should be removed, this "SKIP" |
| 244 // behavior is wrong when the character can't be encoded properly. | 241 // behavior is wrong when the character can't be encoded properly. |
| 245 std::string encoded; | 242 std::string encoded; |
| 246 if (!base::UTF16ToCodepage(text, codepage, | 243 if (!base::UTF16ToCodepage(text, codepage, |
| 247 base::OnStringConversionError::SKIP, &encoded)) | 244 base::OnStringConversionError::SKIP, &encoded)) |
| 248 return false; | 245 return false; |
| 249 | 246 |
| 250 escaped->assign(UTF8ToUTF16(Escape(encoded, kQueryCharmap, true))); | 247 escaped->assign(UTF8ToUTF16(Escape(encoded, kQueryCharmap, use_plus))); |
| 251 return true; | 248 return true; |
| 252 } | 249 } |
| 253 | 250 |
| 254 string16 UnescapeAndDecodeUTF8URLComponent(const std::string& text, | 251 string16 UnescapeAndDecodeUTF8URLComponent(const std::string& text, |
| 255 UnescapeRule::Type rules, | 252 UnescapeRule::Type rules, |
| 256 size_t* offset_for_adjustment) { | 253 size_t* offset_for_adjustment) { |
| 257 std::wstring result; | 254 std::wstring result; |
| 258 size_t original_offset = offset_for_adjustment ? *offset_for_adjustment : 0; | 255 size_t original_offset = offset_for_adjustment ? *offset_for_adjustment : 0; |
| 259 std::string unescaped_url( | 256 std::string unescaped_url( |
| 260 UnescapeURLImpl(text, rules, offset_for_adjustment)); | 257 UnescapeURLImpl(text, rules, offset_for_adjustment)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 return result; | 316 return result; |
| 320 } | 317 } |
| 321 | 318 |
| 322 std::string EscapeForHTML(const std::string& input) { | 319 std::string EscapeForHTML(const std::string& input) { |
| 323 return EscapeForHTMLImpl(input); | 320 return EscapeForHTMLImpl(input); |
| 324 } | 321 } |
| 325 | 322 |
| 326 string16 EscapeForHTML(const string16& input) { | 323 string16 EscapeForHTML(const string16& input) { |
| 327 return EscapeForHTMLImpl(input); | 324 return EscapeForHTMLImpl(input); |
| 328 } | 325 } |
| OLD | NEW |