| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "net/base/escape.h" | 7 #include "net/base/escape.h" |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 "%7B%7C%7D~%7F%80%FF"); | 108 "%7B%7C%7D~%7F%80%FF"); |
| 109 } | 109 } |
| 110 | 110 |
| 111 TEST(Escape, UnescapeURLComponent) { | 111 TEST(Escape, UnescapeURLComponent) { |
| 112 const UnescapeURLCase unescape_cases[] = { | 112 const UnescapeURLCase unescape_cases[] = { |
| 113 {"", UnescapeRule::NORMAL, ""}, | 113 {"", UnescapeRule::NORMAL, ""}, |
| 114 {"%2", UnescapeRule::NORMAL, "%2"}, | 114 {"%2", UnescapeRule::NORMAL, "%2"}, |
| 115 {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"}, | 115 {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"}, |
| 116 {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"}, | 116 {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"}, |
| 117 {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"}, | 117 {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"}, |
| 118 {"Some%20random text %25%3bOK", UnescapeRule::NORMAL, "Some%20random text %2
5;OK"}, | 118 {"Some%20random text %25%3bOK", UnescapeRule::NORMAL, |
| 119 {"Some%20random text %25%3bOK", UnescapeRule::SPACES, "Some random text %25;
OK"}, | 119 "Some%20random text %25;OK"}, |
| 120 {"Some%20random text %25%3bOK", UnescapeRule::URL_SPECIAL_CHARS, "Some%20ran
dom text %;OK"}, | 120 {"Some%20random text %25%3bOK", UnescapeRule::SPACES, |
| 121 {"Some%20random text %25%3bOK", UnescapeRule::SPACES | UnescapeRule::URL_SPE
CIAL_CHARS, "Some random text %;OK"}, | 121 "Some random text %25;OK"}, |
| 122 {"Some%20random text %25%3bOK", UnescapeRule::URL_SPECIAL_CHARS, |
| 123 "Some%20random text %;OK"}, |
| 124 {"Some%20random text %25%3bOK", |
| 125 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS, |
| 126 "Some random text %;OK"}, |
| 122 {"%A0%B1%C2%D3%E4%F5", UnescapeRule::NORMAL, "\xA0\xB1\xC2\xD3\xE4\xF5"}, | 127 {"%A0%B1%C2%D3%E4%F5", UnescapeRule::NORMAL, "\xA0\xB1\xC2\xD3\xE4\xF5"}, |
| 123 {"%Aa%Bb%Cc%Dd%Ee%Ff", UnescapeRule::NORMAL, "\xAa\xBb\xCc\xDd\xEe\xFf"}, | 128 {"%Aa%Bb%Cc%Dd%Ee%Ff", UnescapeRule::NORMAL, "\xAa\xBb\xCc\xDd\xEe\xFf"}, |
| 124 // Certain URL-sensitive characters should not be unescaped unless asked. | 129 // Certain URL-sensitive characters should not be unescaped unless asked. |
| 125 {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", UnescapeRule::SPACES,
"Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"}, | 130 {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", UnescapeRule::SPACES, |
| 126 {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", UnescapeRule::URL_SPEC
IAL_CHARS, "Hello%20%13%10world ## ?? == && %% ++"}, | 131 "Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"}, |
| 132 {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", |
| 133 UnescapeRule::URL_SPECIAL_CHARS, |
| 134 "Hello%20%13%10world ## ?? == && %% ++"}, |
| 127 // Control characters. | 135 // Control characters. |
| 128 {"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::URL_SPECIAL_CHARS, "%01%02
%03%04%05%06%07%08%09 %"}, | 136 {"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::URL_SPECIAL_CHARS, |
| 129 {"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::CONTROL_CHARS, "\x01\x02\x
03\x04\x05\x06\x07\x08\x09 %25"}, | 137 "%01%02%03%04%05%06%07%08%09 %"}, |
| 138 {"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::CONTROL_CHARS, |
| 139 "\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"}, |
| 130 {"Hello%20%13%10%02", UnescapeRule::SPACES, "Hello %13%10%02"}, | 140 {"Hello%20%13%10%02", UnescapeRule::SPACES, "Hello %13%10%02"}, |
| 131 {"Hello%20%13%10%02", UnescapeRule::CONTROL_CHARS, "Hello%20\x13\x10\x02"}, | 141 {"Hello%20%13%10%02", UnescapeRule::CONTROL_CHARS, "Hello%20\x13\x10\x02"}, |
| 132 }; | 142 }; |
| 133 | 143 |
| 134 for (size_t i = 0; i < arraysize(unescape_cases); i++) { | 144 for (size_t i = 0; i < arraysize(unescape_cases); i++) { |
| 135 std::string str(unescape_cases[i].input); | 145 std::string str(unescape_cases[i].input); |
| 136 EXPECT_EQ(std::string(unescape_cases[i].output), | 146 EXPECT_EQ(std::string(unescape_cases[i].output), |
| 137 UnescapeURLComponent(str, unescape_cases[i].rules)); | 147 UnescapeURLComponent(str, unescape_cases[i].rules)); |
| 138 } | 148 } |
| 139 | 149 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 { "<hello>", "<hello>" }, | 226 { "<hello>", "<hello>" }, |
| 217 { "don\'t mess with me", "don't mess with me" }, | 227 { "don\'t mess with me", "don't mess with me" }, |
| 218 }; | 228 }; |
| 219 for (size_t i = 0; i < arraysize(tests); ++i) { | 229 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 220 std::string result = EscapeForHTML(std::string(tests[i].input)); | 230 std::string result = EscapeForHTML(std::string(tests[i].input)); |
| 221 EXPECT_EQ(std::string(tests[i].expected_output), result); | 231 EXPECT_EQ(std::string(tests[i].expected_output), result); |
| 222 } | 232 } |
| 223 } | 233 } |
| 224 | 234 |
| 225 | 235 |
| OLD | NEW |