| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "net/base/escape.h" | 8 #include "net/base/escape.h" |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 size_t output_offset; | 52 size_t output_offset; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 struct EscapeForHTMLCase { | 55 struct EscapeForHTMLCase { |
| 56 const char* input; | 56 const char* input; |
| 57 const char* expected_output; | 57 const char* expected_output; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 TEST(EscapeTest, EscapeTextForFormSubmission) { | 60 TEST(EscapeTest, EscapeTextForFormSubmission) { |
| 61 const EscapeCase escape_cases[] = { | 61 const EscapeCase escape_cases[] = { |
| 62 {"foo", "foo"}, | 62 {"foo", "foo"}, {"foo bar", "foo+bar"}, {"foo++", "foo%2B%2B"}}; |
| 63 {"foo bar", "foo+bar"}, | |
| 64 {"foo++", "foo%2B%2B"} | |
| 65 }; | |
| 66 for (size_t i = 0; i < arraysize(escape_cases); ++i) { | 63 for (size_t i = 0; i < arraysize(escape_cases); ++i) { |
| 67 EscapeCase value = escape_cases[i]; | 64 EscapeCase value = escape_cases[i]; |
| 68 EXPECT_EQ(value.output, EscapeQueryParamValue(value.input, true)); | 65 EXPECT_EQ(value.output, EscapeQueryParamValue(value.input, true)); |
| 69 } | 66 } |
| 70 | 67 |
| 71 const EscapeCase escape_cases_no_plus[] = { | 68 const EscapeCase escape_cases_no_plus[] = { |
| 72 {"foo", "foo"}, | 69 {"foo", "foo"}, {"foo bar", "foo%20bar"}, {"foo++", "foo%2B%2B"}}; |
| 73 {"foo bar", "foo%20bar"}, | |
| 74 {"foo++", "foo%2B%2B"} | |
| 75 }; | |
| 76 for (size_t i = 0; i < arraysize(escape_cases_no_plus); ++i) { | 70 for (size_t i = 0; i < arraysize(escape_cases_no_plus); ++i) { |
| 77 EscapeCase value = escape_cases_no_plus[i]; | 71 EscapeCase value = escape_cases_no_plus[i]; |
| 78 EXPECT_EQ(value.output, EscapeQueryParamValue(value.input, false)); | 72 EXPECT_EQ(value.output, EscapeQueryParamValue(value.input, false)); |
| 79 } | 73 } |
| 80 | 74 |
| 81 // Test all the values in we're supposed to be escaping. | 75 // Test all the values in we're supposed to be escaping. |
| 82 const std::string no_escape( | 76 const std::string no_escape( |
| 83 "abcdefghijklmnopqrstuvwxyz" | 77 "abcdefghijklmnopqrstuvwxyz" |
| 84 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 78 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 85 "0123456789" | 79 "0123456789" |
| 86 "!'()*-._~"); | 80 "!'()*-._~"); |
| 87 for (int i = 0; i < 256; ++i) { | 81 for (int i = 0; i < 256; ++i) { |
| 88 std::string in; | 82 std::string in; |
| 89 in.push_back(i); | 83 in.push_back(i); |
| 90 std::string out = EscapeQueryParamValue(in, true); | 84 std::string out = EscapeQueryParamValue(in, true); |
| 91 if (0 == i) { | 85 if (0 == i) { |
| 92 EXPECT_EQ(out, std::string("%00")); | 86 EXPECT_EQ(out, std::string("%00")); |
| 93 } else if (32 == i) { | 87 } else if (32 == i) { |
| 94 // Spaces are plus escaped like web forms. | 88 // Spaces are plus escaped like web forms. |
| 95 EXPECT_EQ(out, std::string("+")); | 89 EXPECT_EQ(out, std::string("+")); |
| 96 } else if (no_escape.find(in) == std::string::npos) { | 90 } else if (no_escape.find(in) == std::string::npos) { |
| 97 // Check %hex escaping | 91 // Check %hex escaping |
| 98 std::string expected = base::StringPrintf("%%%02X", i); | 92 std::string expected = base::StringPrintf("%%%02X", i); |
| 99 EXPECT_EQ(expected, out); | 93 EXPECT_EQ(expected, out); |
| 100 } else { | 94 } else { |
| 101 // No change for things in the no_escape list. | 95 // No change for things in the no_escape list. |
| 102 EXPECT_EQ(out, in); | 96 EXPECT_EQ(out, in); |
| 103 } | 97 } |
| 104 } | 98 } |
| 105 } | 99 } |
| 106 | 100 |
| 107 TEST(EscapeTest, EscapePath) { | 101 TEST(EscapeTest, EscapePath) { |
| 108 ASSERT_EQ( | 102 ASSERT_EQ( |
| 109 // Most of the character space we care about, un-escaped | 103 // Most of the character space we care about, un-escaped |
| 110 EscapePath( | 104 EscapePath( |
| 111 "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;" | 105 "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;" |
| 112 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 106 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 113 "[\\]^_`abcdefghijklmnopqrstuvwxyz" | 107 "[\\]^_`abcdefghijklmnopqrstuvwxyz" |
| 114 "{|}~\x7f\x80\xff"), | 108 "{|}~\x7f\x80\xff"), |
| 115 // Escaped | 109 // Escaped |
| 116 "%02%0A%1D%20!%22%23$%25&'()*+,-./0123456789%3A;" | 110 "%02%0A%1D%20!%22%23$%25&'()*+,-./0123456789%3A;" |
| 117 "%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 111 "%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 118 "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz" | 112 "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz" |
| 119 "%7B%7C%7D~%7F%80%FF"); | 113 "%7B%7C%7D~%7F%80%FF"); |
| 120 } | 114 } |
| 121 | 115 |
| 122 TEST(EscapeTest, DataURLWithAccentedCharacters) { | 116 TEST(EscapeTest, DataURLWithAccentedCharacters) { |
| 123 const std::string url = | 117 const std::string url = |
| 124 "text/html;charset=utf-8,%3Chtml%3E%3Cbody%3ETonton,%20ton%20th%C3" | 118 "text/html;charset=utf-8,%3Chtml%3E%3Cbody%3ETonton,%20ton%20th%C3" |
| 125 "%A9%20t'a-t-il%20%C3%B4t%C3%A9%20ta%20toux%20"; | 119 "%A9%20t'a-t-il%20%C3%B4t%C3%A9%20ta%20toux%20"; |
| 126 | 120 |
| 127 base::OffsetAdjuster::Adjustments adjustments; | 121 base::OffsetAdjuster::Adjustments adjustments; |
| 128 net::UnescapeAndDecodeUTF8URLComponentWithAdjustments( | 122 net::UnescapeAndDecodeUTF8URLComponentWithAdjustments( |
| 129 url, UnescapeRule::SPACES, &adjustments); | 123 url, UnescapeRule::SPACES, &adjustments); |
| 130 } | 124 } |
| 131 | 125 |
| 132 TEST(EscapeTest, EscapeUrlEncodedData) { | 126 TEST(EscapeTest, EscapeUrlEncodedData) { |
| 133 ASSERT_EQ( | 127 ASSERT_EQ( |
| 134 // Most of the character space we care about, un-escaped | 128 // Most of the character space we care about, un-escaped |
| 135 EscapeUrlEncodedData( | 129 EscapeUrlEncodedData( |
| 136 "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;" | 130 "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;" |
| 137 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 131 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 138 "[\\]^_`abcdefghijklmnopqrstuvwxyz" | 132 "[\\]^_`abcdefghijklmnopqrstuvwxyz" |
| 139 "{|}~\x7f\x80\xff", true), | 133 "{|}~\x7f\x80\xff", |
| 140 // Escaped | 134 true), |
| 141 "%02%0A%1D+!%22%23%24%25%26%27()*%2B,-./0123456789:%3B" | 135 // Escaped |
| 142 "%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 136 "%02%0A%1D+!%22%23%24%25%26%27()*%2B,-./0123456789:%3B" |
| 143 "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz" | 137 "%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 144 "%7B%7C%7D~%7F%80%FF"); | 138 "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz" |
| 139 "%7B%7C%7D~%7F%80%FF"); |
| 145 } | 140 } |
| 146 | 141 |
| 147 TEST(EscapeTest, EscapeUrlEncodedDataSpace) { | 142 TEST(EscapeTest, EscapeUrlEncodedDataSpace) { |
| 148 ASSERT_EQ(EscapeUrlEncodedData("a b", true), "a+b"); | 143 ASSERT_EQ(EscapeUrlEncodedData("a b", true), "a+b"); |
| 149 ASSERT_EQ(EscapeUrlEncodedData("a b", false), "a%20b"); | 144 ASSERT_EQ(EscapeUrlEncodedData("a b", false), "a%20b"); |
| 150 } | 145 } |
| 151 | 146 |
| 152 TEST(EscapeTest, UnescapeURLComponentASCII) { | 147 TEST(EscapeTest, UnescapeURLComponentASCII) { |
| 153 const UnescapeURLCaseASCII unescape_cases[] = { | 148 const UnescapeURLCaseASCII unescape_cases[] = { |
| 154 {"", UnescapeRule::NORMAL, ""}, | 149 {"", UnescapeRule::NORMAL, ""}, |
| 155 {"%2", UnescapeRule::NORMAL, "%2"}, | 150 {"%2", UnescapeRule::NORMAL, "%2"}, |
| 156 {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"}, | 151 {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"}, |
| 157 {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"}, | 152 {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"}, |
| 158 {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"}, | 153 {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"}, |
| 159 {"Some%20random text %25%2dOK", UnescapeRule::NONE, | 154 {"Some%20random text %25%2dOK", |
| 160 "Some%20random text %25%2dOK"}, | 155 UnescapeRule::NONE, |
| 161 {"Some%20random text %25%2dOK", UnescapeRule::NORMAL, | 156 "Some%20random text %25%2dOK"}, |
| 162 "Some%20random text %25-OK"}, | 157 {"Some%20random text %25%2dOK", |
| 163 {"Some%20random text %25%2dOK", UnescapeRule::SPACES, | 158 UnescapeRule::NORMAL, |
| 164 "Some random text %25-OK"}, | 159 "Some%20random text %25-OK"}, |
| 165 {"Some%20random text %25%2dOK", UnescapeRule::URL_SPECIAL_CHARS, | 160 {"Some%20random text %25%2dOK", |
| 166 "Some%20random text %-OK"}, | 161 UnescapeRule::SPACES, |
| 167 {"Some%20random text %25%2dOK", | 162 "Some random text %25-OK"}, |
| 168 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS, | 163 {"Some%20random text %25%2dOK", |
| 169 "Some random text %-OK"}, | 164 UnescapeRule::URL_SPECIAL_CHARS, |
| 170 {"%A0%B1%C2%D3%E4%F5", UnescapeRule::NORMAL, "\xA0\xB1\xC2\xD3\xE4\xF5"}, | 165 "Some%20random text %-OK"}, |
| 171 {"%Aa%Bb%Cc%Dd%Ee%Ff", UnescapeRule::NORMAL, "\xAa\xBb\xCc\xDd\xEe\xFf"}, | 166 {"Some%20random text %25%2dOK", |
| 172 // Certain URL-sensitive characters should not be unescaped unless asked. | 167 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS, |
| 173 {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", UnescapeRule::SPACES, | 168 "Some random text %-OK"}, |
| 174 "Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"}, | 169 {"%A0%B1%C2%D3%E4%F5", UnescapeRule::NORMAL, "\xA0\xB1\xC2\xD3\xE4\xF5"}, |
| 175 {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", | 170 {"%Aa%Bb%Cc%Dd%Ee%Ff", UnescapeRule::NORMAL, "\xAa\xBb\xCc\xDd\xEe\xFf"}, |
| 176 UnescapeRule::URL_SPECIAL_CHARS, | 171 // Certain URL-sensitive characters should not be unescaped unless asked. |
| 177 "Hello%20%13%10world ## ?? == && %% ++"}, | 172 {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", |
| 178 // We can neither escape nor unescape '@' since some websites expect it to | 173 UnescapeRule::SPACES, |
| 179 // be preserved as either '@' or "%40". | 174 "Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"}, |
| 180 // See http://b/996720 and http://crbug.com/23933 . | 175 {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", |
| 181 {"me@my%40example", UnescapeRule::NORMAL, "me@my%40example"}, | 176 UnescapeRule::URL_SPECIAL_CHARS, |
| 182 // Control characters. | 177 "Hello%20%13%10world ## ?? == && %% ++"}, |
| 183 {"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::URL_SPECIAL_CHARS, | 178 // We can neither escape nor unescape '@' since some websites expect it to |
| 184 "%01%02%03%04%05%06%07%08%09 %"}, | 179 // be preserved as either '@' or "%40". |
| 185 {"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::CONTROL_CHARS, | 180 // See http://b/996720 and http://crbug.com/23933 . |
| 186 "\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"}, | 181 {"me@my%40example", UnescapeRule::NORMAL, "me@my%40example"}, |
| 187 {"Hello%20%13%10%02", UnescapeRule::SPACES, "Hello %13%10%02"}, | 182 // Control characters. |
| 188 {"Hello%20%13%10%02", UnescapeRule::CONTROL_CHARS, "Hello%20\x13\x10\x02"}, | 183 {"%01%02%03%04%05%06%07%08%09 %25", |
| 184 UnescapeRule::URL_SPECIAL_CHARS, |
| 185 "%01%02%03%04%05%06%07%08%09 %"}, |
| 186 {"%01%02%03%04%05%06%07%08%09 %25", |
| 187 UnescapeRule::CONTROL_CHARS, |
| 188 "\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"}, |
| 189 {"Hello%20%13%10%02", UnescapeRule::SPACES, "Hello %13%10%02"}, |
| 190 {"Hello%20%13%10%02", |
| 191 UnescapeRule::CONTROL_CHARS, |
| 192 "Hello%20\x13\x10\x02"}, |
| 189 }; | 193 }; |
| 190 | 194 |
| 191 for (size_t i = 0; i < arraysize(unescape_cases); i++) { | 195 for (size_t i = 0; i < arraysize(unescape_cases); i++) { |
| 192 std::string str(unescape_cases[i].input); | 196 std::string str(unescape_cases[i].input); |
| 193 EXPECT_EQ(std::string(unescape_cases[i].output), | 197 EXPECT_EQ(std::string(unescape_cases[i].output), |
| 194 UnescapeURLComponent(str, unescape_cases[i].rules)); | 198 UnescapeURLComponent(str, unescape_cases[i].rules)); |
| 195 } | 199 } |
| 196 | 200 |
| 197 // Test the NULL character unescaping (which wouldn't work above since those | 201 // Test the NULL character unescaping (which wouldn't work above since those |
| 198 // are just char pointers). | 202 // are just char pointers). |
| (...skipping 10 matching lines...) Expand all Loading... |
| 209 | 213 |
| 210 // When we're not unescaping NULLs. | 214 // When we're not unescaping NULLs. |
| 211 expected = "Null"; | 215 expected = "Null"; |
| 212 expected.push_back(0); | 216 expected.push_back(0); |
| 213 expected.append("%009Test"); | 217 expected.append("%009Test"); |
| 214 EXPECT_EQ(expected, UnescapeURLComponent(input, UnescapeRule::NORMAL)); | 218 EXPECT_EQ(expected, UnescapeURLComponent(input, UnescapeRule::NORMAL)); |
| 215 } | 219 } |
| 216 | 220 |
| 217 TEST(EscapeTest, UnescapeURLComponent) { | 221 TEST(EscapeTest, UnescapeURLComponent) { |
| 218 const UnescapeURLCase unescape_cases[] = { | 222 const UnescapeURLCase unescape_cases[] = { |
| 219 {L"", UnescapeRule::NORMAL, L""}, | 223 {L"", UnescapeRule::NORMAL, L""}, |
| 220 {L"%2", UnescapeRule::NORMAL, L"%2"}, | 224 {L"%2", UnescapeRule::NORMAL, L"%2"}, |
| 221 {L"%%%%%%", UnescapeRule::NORMAL, L"%%%%%%"}, | 225 {L"%%%%%%", UnescapeRule::NORMAL, L"%%%%%%"}, |
| 222 {L"Don't escape anything", UnescapeRule::NORMAL, L"Don't escape anything"}, | 226 {L"Don't escape anything", |
| 223 {L"Invalid %escape %2", UnescapeRule::NORMAL, L"Invalid %escape %2"}, | 227 UnescapeRule::NORMAL, |
| 224 {L"Some%20random text %25%2dOK", UnescapeRule::NONE, | 228 L"Don't escape anything"}, |
| 225 L"Some%20random text %25%2dOK"}, | 229 {L"Invalid %escape %2", UnescapeRule::NORMAL, L"Invalid %escape %2"}, |
| 226 {L"Some%20random text %25%2dOK", UnescapeRule::NORMAL, | 230 {L"Some%20random text %25%2dOK", |
| 227 L"Some%20random text %25-OK"}, | 231 UnescapeRule::NONE, |
| 228 {L"Some%20random text %25%E2%80", UnescapeRule::NORMAL, | 232 L"Some%20random text %25%2dOK"}, |
| 229 L"Some%20random text %25\xE2\x80"}, | 233 {L"Some%20random text %25%2dOK", |
| 230 {L"Some%20random text %25%E2%80OK", UnescapeRule::NORMAL, | 234 UnescapeRule::NORMAL, |
| 231 L"Some%20random text %25\xE2\x80OK"}, | 235 L"Some%20random text %25-OK"}, |
| 232 {L"Some%20random text %25%E2%80%84OK", UnescapeRule::NORMAL, | 236 {L"Some%20random text %25%E2%80", |
| 233 L"Some%20random text %25\xE2\x80\x84OK"}, | 237 UnescapeRule::NORMAL, |
| 238 L"Some%20random text %25\xE2\x80"}, |
| 239 {L"Some%20random text %25%E2%80OK", |
| 240 UnescapeRule::NORMAL, |
| 241 L"Some%20random text %25\xE2\x80OK"}, |
| 242 {L"Some%20random text %25%E2%80%84OK", |
| 243 UnescapeRule::NORMAL, |
| 244 L"Some%20random text %25\xE2\x80\x84OK"}, |
| 234 | 245 |
| 235 // BiDi Control characters should not be unescaped unless explicity told to | 246 // BiDi Control characters should not be unescaped unless explicity told |
| 236 // do so with UnescapeRule::CONTROL_CHARS | 247 // to |
| 237 {L"Some%20random text %25%D8%9COK", UnescapeRule::NORMAL, | 248 // do so with UnescapeRule::CONTROL_CHARS |
| 238 L"Some%20random text %25%D8%9COK"}, | 249 {L"Some%20random text %25%D8%9COK", |
| 239 {L"Some%20random text %25%E2%80%8EOK", UnescapeRule::NORMAL, | 250 UnescapeRule::NORMAL, |
| 240 L"Some%20random text %25%E2%80%8EOK"}, | 251 L"Some%20random text %25%D8%9COK"}, |
| 241 {L"Some%20random text %25%E2%80%8FOK", UnescapeRule::NORMAL, | 252 {L"Some%20random text %25%E2%80%8EOK", |
| 242 L"Some%20random text %25%E2%80%8FOK"}, | 253 UnescapeRule::NORMAL, |
| 243 {L"Some%20random text %25%E2%80%AAOK", UnescapeRule::NORMAL, | 254 L"Some%20random text %25%E2%80%8EOK"}, |
| 244 L"Some%20random text %25%E2%80%AAOK"}, | 255 {L"Some%20random text %25%E2%80%8FOK", |
| 245 {L"Some%20random text %25%E2%80%ABOK", UnescapeRule::NORMAL, | 256 UnescapeRule::NORMAL, |
| 246 L"Some%20random text %25%E2%80%ABOK"}, | 257 L"Some%20random text %25%E2%80%8FOK"}, |
| 247 {L"Some%20random text %25%E2%80%AEOK", UnescapeRule::NORMAL, | 258 {L"Some%20random text %25%E2%80%AAOK", |
| 248 L"Some%20random text %25%E2%80%AEOK"}, | 259 UnescapeRule::NORMAL, |
| 249 {L"Some%20random text %25%E2%81%A6OK", UnescapeRule::NORMAL, | 260 L"Some%20random text %25%E2%80%AAOK"}, |
| 250 L"Some%20random text %25%E2%81%A6OK"}, | 261 {L"Some%20random text %25%E2%80%ABOK", |
| 251 {L"Some%20random text %25%E2%81%A9OK", UnescapeRule::NORMAL, | 262 UnescapeRule::NORMAL, |
| 252 L"Some%20random text %25%E2%81%A9OK"}, | 263 L"Some%20random text %25%E2%80%ABOK"}, |
| 253 // UnescapeRule::CONTROL_CHARS should unescape BiDi Control characters. | 264 {L"Some%20random text %25%E2%80%AEOK", |
| 254 {L"Some%20random text %25%D8%9COK", | 265 UnescapeRule::NORMAL, |
| 255 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, | 266 L"Some%20random text %25%E2%80%AEOK"}, |
| 256 L"Some%20random text %25\xD8\x9COK"}, | 267 {L"Some%20random text %25%E2%81%A6OK", |
| 257 {L"Some%20random text %25%E2%80%8EOK", | 268 UnescapeRule::NORMAL, |
| 258 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, | 269 L"Some%20random text %25%E2%81%A6OK"}, |
| 259 L"Some%20random text %25\xE2\x80\x8EOK"}, | 270 {L"Some%20random text %25%E2%81%A9OK", |
| 260 {L"Some%20random text %25%E2%80%8FOK", | 271 UnescapeRule::NORMAL, |
| 261 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, | 272 L"Some%20random text %25%E2%81%A9OK"}, |
| 262 L"Some%20random text %25\xE2\x80\x8FOK"}, | 273 // UnescapeRule::CONTROL_CHARS should unescape BiDi Control characters. |
| 263 {L"Some%20random text %25%E2%80%AAOK", | 274 {L"Some%20random text %25%D8%9COK", |
| 264 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, | 275 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, |
| 265 L"Some%20random text %25\xE2\x80\xAAOK"}, | 276 L"Some%20random text %25\xD8\x9COK"}, |
| 266 {L"Some%20random text %25%E2%80%ABOK", | 277 {L"Some%20random text %25%E2%80%8EOK", |
| 267 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, | 278 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, |
| 268 L"Some%20random text %25\xE2\x80\xABOK"}, | 279 L"Some%20random text %25\xE2\x80\x8EOK"}, |
| 269 {L"Some%20random text %25%E2%80%AEOK", | 280 {L"Some%20random text %25%E2%80%8FOK", |
| 270 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, | 281 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, |
| 271 L"Some%20random text %25\xE2\x80\xAEOK"}, | 282 L"Some%20random text %25\xE2\x80\x8FOK"}, |
| 272 {L"Some%20random text %25%E2%81%A6OK", | 283 {L"Some%20random text %25%E2%80%AAOK", |
| 273 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, | 284 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, |
| 274 L"Some%20random text %25\xE2\x81\xA6OK"}, | 285 L"Some%20random text %25\xE2\x80\xAAOK"}, |
| 275 {L"Some%20random text %25%E2%81%A9OK", | 286 {L"Some%20random text %25%E2%80%ABOK", |
| 276 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, | 287 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, |
| 277 L"Some%20random text %25\xE2\x81\xA9OK"}, | 288 L"Some%20random text %25\xE2\x80\xABOK"}, |
| 289 {L"Some%20random text %25%E2%80%AEOK", |
| 290 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, |
| 291 L"Some%20random text %25\xE2\x80\xAEOK"}, |
| 292 {L"Some%20random text %25%E2%81%A6OK", |
| 293 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, |
| 294 L"Some%20random text %25\xE2\x81\xA6OK"}, |
| 295 {L"Some%20random text %25%E2%81%A9OK", |
| 296 UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS, |
| 297 L"Some%20random text %25\xE2\x81\xA9OK"}, |
| 278 | 298 |
| 279 {L"Some%20random text %25%2dOK", UnescapeRule::SPACES, | 299 {L"Some%20random text %25%2dOK", |
| 280 L"Some random text %25-OK"}, | 300 UnescapeRule::SPACES, |
| 281 {L"Some%20random text %25%2dOK", UnescapeRule::URL_SPECIAL_CHARS, | 301 L"Some random text %25-OK"}, |
| 282 L"Some%20random text %-OK"}, | 302 {L"Some%20random text %25%2dOK", |
| 283 {L"Some%20random text %25%2dOK", | 303 UnescapeRule::URL_SPECIAL_CHARS, |
| 284 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS, | 304 L"Some%20random text %-OK"}, |
| 285 L"Some random text %-OK"}, | 305 {L"Some%20random text %25%2dOK", |
| 286 {L"%A0%B1%C2%D3%E4%F5", UnescapeRule::NORMAL, L"\xA0\xB1\xC2\xD3\xE4\xF5"}, | 306 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS, |
| 287 {L"%Aa%Bb%Cc%Dd%Ee%Ff", UnescapeRule::NORMAL, L"\xAa\xBb\xCc\xDd\xEe\xFf"}, | 307 L"Some random text %-OK"}, |
| 288 // Certain URL-sensitive characters should not be unescaped unless asked. | 308 {L"%A0%B1%C2%D3%E4%F5", |
| 289 {L"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", UnescapeRule::SPACES, | 309 UnescapeRule::NORMAL, |
| 290 L"Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"}, | 310 L"\xA0\xB1\xC2\xD3\xE4\xF5"}, |
| 291 {L"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", | 311 {L"%Aa%Bb%Cc%Dd%Ee%Ff", |
| 292 UnescapeRule::URL_SPECIAL_CHARS, | 312 UnescapeRule::NORMAL, |
| 293 L"Hello%20%13%10world ## ?? == && %% ++"}, | 313 L"\xAa\xBb\xCc\xDd\xEe\xFf"}, |
| 294 // We can neither escape nor unescape '@' since some websites expect it to | 314 // Certain URL-sensitive characters should not be unescaped unless asked. |
| 295 // be preserved as either '@' or "%40". | 315 {L"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", |
| 296 // See http://b/996720 and http://crbug.com/23933 . | 316 UnescapeRule::SPACES, |
| 297 {L"me@my%40example", UnescapeRule::NORMAL, L"me@my%40example"}, | 317 L"Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"}, |
| 298 // Control characters. | 318 {L"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", |
| 299 {L"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::URL_SPECIAL_CHARS, | 319 UnescapeRule::URL_SPECIAL_CHARS, |
| 300 L"%01%02%03%04%05%06%07%08%09 %"}, | 320 L"Hello%20%13%10world ## ?? == && %% ++"}, |
| 301 {L"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::CONTROL_CHARS, | 321 // We can neither escape nor unescape '@' since some websites expect it to |
| 302 L"\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"}, | 322 // be preserved as either '@' or "%40". |
| 303 {L"Hello%20%13%10%02", UnescapeRule::SPACES, L"Hello %13%10%02"}, | 323 // See http://b/996720 and http://crbug.com/23933 . |
| 304 {L"Hello%20%13%10%02", UnescapeRule::CONTROL_CHARS, | 324 {L"me@my%40example", UnescapeRule::NORMAL, L"me@my%40example"}, |
| 305 L"Hello%20\x13\x10\x02"}, | 325 // Control characters. |
| 306 {L"Hello\x9824\x9827", UnescapeRule::CONTROL_CHARS, | 326 {L"%01%02%03%04%05%06%07%08%09 %25", |
| 307 L"Hello\x9824\x9827"}, | 327 UnescapeRule::URL_SPECIAL_CHARS, |
| 328 L"%01%02%03%04%05%06%07%08%09 %"}, |
| 329 {L"%01%02%03%04%05%06%07%08%09 %25", |
| 330 UnescapeRule::CONTROL_CHARS, |
| 331 L"\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"}, |
| 332 {L"Hello%20%13%10%02", UnescapeRule::SPACES, L"Hello %13%10%02"}, |
| 333 {L"Hello%20%13%10%02", |
| 334 UnescapeRule::CONTROL_CHARS, |
| 335 L"Hello%20\x13\x10\x02"}, |
| 336 {L"Hello\x9824\x9827", UnescapeRule::CONTROL_CHARS, L"Hello\x9824\x9827"}, |
| 308 }; | 337 }; |
| 309 | 338 |
| 310 for (size_t i = 0; i < arraysize(unescape_cases); i++) { | 339 for (size_t i = 0; i < arraysize(unescape_cases); i++) { |
| 311 base::string16 str(base::WideToUTF16(unescape_cases[i].input)); | 340 base::string16 str(base::WideToUTF16(unescape_cases[i].input)); |
| 312 EXPECT_EQ(base::WideToUTF16(unescape_cases[i].output), | 341 EXPECT_EQ(base::WideToUTF16(unescape_cases[i].output), |
| 313 UnescapeURLComponent(str, unescape_cases[i].rules)); | 342 UnescapeURLComponent(str, unescape_cases[i].rules)); |
| 314 } | 343 } |
| 315 | 344 |
| 316 // Test the NULL character unescaping (which wouldn't work above since those | 345 // Test the NULL character unescaping (which wouldn't work above since those |
| 317 // are just char pointers). | 346 // are just char pointers). |
| (...skipping 10 matching lines...) Expand all Loading... |
| 328 | 357 |
| 329 // When we're not unescaping NULLs. | 358 // When we're not unescaping NULLs. |
| 330 expected = base::WideToUTF16(L"Null"); | 359 expected = base::WideToUTF16(L"Null"); |
| 331 expected.push_back(0); | 360 expected.push_back(0); |
| 332 expected.append(base::WideToUTF16(L"%009Test")); | 361 expected.append(base::WideToUTF16(L"%009Test")); |
| 333 EXPECT_EQ(expected, UnescapeURLComponent(input, UnescapeRule::NORMAL)); | 362 EXPECT_EQ(expected, UnescapeURLComponent(input, UnescapeRule::NORMAL)); |
| 334 } | 363 } |
| 335 | 364 |
| 336 TEST(EscapeTest, UnescapeAndDecodeUTF8URLComponent) { | 365 TEST(EscapeTest, UnescapeAndDecodeUTF8URLComponent) { |
| 337 const UnescapeAndDecodeCase unescape_cases[] = { | 366 const UnescapeAndDecodeCase unescape_cases[] = { |
| 338 { "%", | 367 {"%", "%", "%", L"%"}, |
| 339 "%", | 368 {"+", "+", " ", L"+"}, |
| 340 "%", | 369 {"%2+", "%2+", "%2 ", L"%2+"}, |
| 341 L"%"}, | 370 {"+%%%+%%%", "+%%%+%%%", " %%% %%%", L"+%%%+%%%"}, |
| 342 { "+", | 371 {"Don't escape anything", |
| 343 "+", | 372 "Don't escape anything", |
| 344 " ", | 373 "Don't escape anything", |
| 345 L"+"}, | 374 L"Don't escape anything"}, |
| 346 { "%2+", | 375 {"+Invalid %escape %2+", |
| 347 "%2+", | 376 "+Invalid %escape %2+", |
| 348 "%2 ", | 377 " Invalid %escape %2 ", |
| 349 L"%2+"}, | 378 L"+Invalid %escape %2+"}, |
| 350 { "+%%%+%%%", | 379 {"Some random text %25%2dOK", |
| 351 "+%%%+%%%", | 380 "Some random text %25-OK", |
| 352 " %%% %%%", | 381 "Some random text %25-OK", |
| 353 L"+%%%+%%%"}, | 382 L"Some random text %25-OK"}, |
| 354 { "Don't escape anything", | 383 {"%01%02%03%04%05%06%07%08%09", |
| 355 "Don't escape anything", | 384 "%01%02%03%04%05%06%07%08%09", |
| 356 "Don't escape anything", | 385 "%01%02%03%04%05%06%07%08%09", |
| 357 L"Don't escape anything"}, | 386 L"%01%02%03%04%05%06%07%08%09"}, |
| 358 { "+Invalid %escape %2+", | 387 {"%E4%BD%A0+%E5%A5%BD", |
| 359 "+Invalid %escape %2+", | 388 "\xE4\xBD\xA0+\xE5\xA5\xBD", |
| 360 " Invalid %escape %2 ", | 389 "\xE4\xBD\xA0 \xE5\xA5\xBD", |
| 361 L"+Invalid %escape %2+"}, | 390 L"\x4f60+\x597d"}, |
| 362 { "Some random text %25%2dOK", | 391 {"%ED%ED", // Invalid UTF-8. |
| 363 "Some random text %25-OK", | 392 "\xED\xED", |
| 364 "Some random text %25-OK", | 393 "\xED\xED", |
| 365 L"Some random text %25-OK"}, | 394 L"%ED%ED"}, // Invalid UTF-8 -> kept unescaped. |
| 366 { "%01%02%03%04%05%06%07%08%09", | |
| 367 "%01%02%03%04%05%06%07%08%09", | |
| 368 "%01%02%03%04%05%06%07%08%09", | |
| 369 L"%01%02%03%04%05%06%07%08%09"}, | |
| 370 { "%E4%BD%A0+%E5%A5%BD", | |
| 371 "\xE4\xBD\xA0+\xE5\xA5\xBD", | |
| 372 "\xE4\xBD\xA0 \xE5\xA5\xBD", | |
| 373 L"\x4f60+\x597d"}, | |
| 374 { "%ED%ED", // Invalid UTF-8. | |
| 375 "\xED\xED", | |
| 376 "\xED\xED", | |
| 377 L"%ED%ED"}, // Invalid UTF-8 -> kept unescaped. | |
| 378 }; | 395 }; |
| 379 | 396 |
| 380 for (size_t i = 0; i < arraysize(unescape_cases); i++) { | 397 for (size_t i = 0; i < arraysize(unescape_cases); i++) { |
| 381 std::string unescaped = UnescapeURLComponent(unescape_cases[i].input, | 398 std::string unescaped = |
| 382 UnescapeRule::NORMAL); | 399 UnescapeURLComponent(unescape_cases[i].input, UnescapeRule::NORMAL); |
| 383 EXPECT_EQ(std::string(unescape_cases[i].url_unescaped), unescaped); | 400 EXPECT_EQ(std::string(unescape_cases[i].url_unescaped), unescaped); |
| 384 | 401 |
| 385 unescaped = UnescapeURLComponent(unescape_cases[i].input, | 402 unescaped = UnescapeURLComponent(unescape_cases[i].input, |
| 386 UnescapeRule::REPLACE_PLUS_WITH_SPACE); | 403 UnescapeRule::REPLACE_PLUS_WITH_SPACE); |
| 387 EXPECT_EQ(std::string(unescape_cases[i].query_unescaped), unescaped); | 404 EXPECT_EQ(std::string(unescape_cases[i].query_unescaped), unescaped); |
| 388 | 405 |
| 389 // TODO: Need to test unescape_spaces and unescape_percent. | 406 // TODO: Need to test unescape_spaces and unescape_percent. |
| 390 base::string16 decoded = UnescapeAndDecodeUTF8URLComponent( | 407 base::string16 decoded = UnescapeAndDecodeUTF8URLComponent( |
| 391 unescape_cases[i].input, UnescapeRule::NORMAL); | 408 unescape_cases[i].input, UnescapeRule::NORMAL); |
| 392 EXPECT_EQ(base::WideToUTF16(unescape_cases[i].decoded), decoded); | 409 EXPECT_EQ(base::WideToUTF16(unescape_cases[i].decoded), decoded); |
| 393 } | 410 } |
| 394 } | 411 } |
| 395 | 412 |
| 396 TEST(EscapeTest, AdjustOffset) { | 413 TEST(EscapeTest, AdjustOffset) { |
| 397 const AdjustOffsetCase adjust_cases[] = { | 414 const AdjustOffsetCase adjust_cases[] = { |
| 398 {"", 0, 0}, | 415 {"", 0, 0}, |
| 399 {"test", 0, 0}, | 416 {"test", 0, 0}, |
| 400 {"test", 2, 2}, | 417 {"test", 2, 2}, |
| 401 {"test", 4, 4}, | 418 {"test", 4, 4}, |
| 402 {"test", std::string::npos, std::string::npos}, | 419 {"test", std::string::npos, std::string::npos}, |
| 403 {"%2dtest", 6, 4}, | 420 {"%2dtest", 6, 4}, |
| 404 {"%2dtest", 3, 1}, | 421 {"%2dtest", 3, 1}, |
| 405 {"%2dtest", 2, std::string::npos}, | 422 {"%2dtest", 2, std::string::npos}, |
| 406 {"%2dtest", 1, std::string::npos}, | 423 {"%2dtest", 1, std::string::npos}, |
| 407 {"%2dtest", 0, 0}, | 424 {"%2dtest", 0, 0}, |
| 408 {"test%2d", 2, 2}, | 425 {"test%2d", 2, 2}, |
| 409 {"%E4%BD%A0+%E5%A5%BD", 9, 1}, | 426 {"%E4%BD%A0+%E5%A5%BD", 9, 1}, |
| 410 {"%E4%BD%A0+%E5%A5%BD", 6, std::string::npos}, | 427 {"%E4%BD%A0+%E5%A5%BD", 6, std::string::npos}, |
| 411 {"%E4%BD%A0+%E5%A5%BD", 0, 0}, | 428 {"%E4%BD%A0+%E5%A5%BD", 0, 0}, |
| 412 {"%E4%BD%A0+%E5%A5%BD", 10, 2}, | 429 {"%E4%BD%A0+%E5%A5%BD", 10, 2}, |
| 413 {"%E4%BD%A0+%E5%A5%BD", 19, 3}, | 430 {"%E4%BD%A0+%E5%A5%BD", 19, 3}, |
| 414 | 431 |
| 415 {"hi%41test%E4%BD%A0+%E5%A5%BD", 18, 8}, | 432 {"hi%41test%E4%BD%A0+%E5%A5%BD", 18, 8}, |
| 416 {"hi%41test%E4%BD%A0+%E5%A5%BD", 15, std::string::npos}, | 433 {"hi%41test%E4%BD%A0+%E5%A5%BD", 15, std::string::npos}, |
| 417 {"hi%41test%E4%BD%A0+%E5%A5%BD", 9, 7}, | 434 {"hi%41test%E4%BD%A0+%E5%A5%BD", 9, 7}, |
| 418 {"hi%41test%E4%BD%A0+%E5%A5%BD", 19, 9}, | 435 {"hi%41test%E4%BD%A0+%E5%A5%BD", 19, 9}, |
| 419 {"hi%41test%E4%BD%A0+%E5%A5%BD", 28, 10}, | 436 {"hi%41test%E4%BD%A0+%E5%A5%BD", 28, 10}, |
| 420 {"hi%41test%E4%BD%A0+%E5%A5%BD", 0, 0}, | 437 {"hi%41test%E4%BD%A0+%E5%A5%BD", 0, 0}, |
| 421 {"hi%41test%E4%BD%A0+%E5%A5%BD", 2, 2}, | 438 {"hi%41test%E4%BD%A0+%E5%A5%BD", 2, 2}, |
| 422 {"hi%41test%E4%BD%A0+%E5%A5%BD", 3, std::string::npos}, | 439 {"hi%41test%E4%BD%A0+%E5%A5%BD", 3, std::string::npos}, |
| 423 {"hi%41test%E4%BD%A0+%E5%A5%BD", 5, 3}, | 440 {"hi%41test%E4%BD%A0+%E5%A5%BD", 5, 3}, |
| 424 | 441 |
| 425 {"%E4%BD%A0+%E5%A5%BDhi%41test", 9, 1}, | 442 {"%E4%BD%A0+%E5%A5%BDhi%41test", 9, 1}, |
| 426 {"%E4%BD%A0+%E5%A5%BDhi%41test", 6, std::string::npos}, | 443 {"%E4%BD%A0+%E5%A5%BDhi%41test", 6, std::string::npos}, |
| 427 {"%E4%BD%A0+%E5%A5%BDhi%41test", 0, 0}, | 444 {"%E4%BD%A0+%E5%A5%BDhi%41test", 0, 0}, |
| 428 {"%E4%BD%A0+%E5%A5%BDhi%41test", 10, 2}, | 445 {"%E4%BD%A0+%E5%A5%BDhi%41test", 10, 2}, |
| 429 {"%E4%BD%A0+%E5%A5%BDhi%41test", 19, 3}, | 446 {"%E4%BD%A0+%E5%A5%BDhi%41test", 19, 3}, |
| 430 {"%E4%BD%A0+%E5%A5%BDhi%41test", 21, 5}, | 447 {"%E4%BD%A0+%E5%A5%BDhi%41test", 21, 5}, |
| 431 {"%E4%BD%A0+%E5%A5%BDhi%41test", 22, std::string::npos}, | 448 {"%E4%BD%A0+%E5%A5%BDhi%41test", 22, std::string::npos}, |
| 432 {"%E4%BD%A0+%E5%A5%BDhi%41test", 24, 6}, | 449 {"%E4%BD%A0+%E5%A5%BDhi%41test", 24, 6}, |
| 433 {"%E4%BD%A0+%E5%A5%BDhi%41test", 28, 10}, | 450 {"%E4%BD%A0+%E5%A5%BDhi%41test", 28, 10}, |
| 434 | 451 |
| 435 {"%ED%B0%80+%E5%A5%BD", 6, 6}, // not convertable to UTF-8 | 452 {"%ED%B0%80+%E5%A5%BD", 6, 6}, // not convertable to UTF-8 |
| 436 }; | 453 }; |
| 437 | 454 |
| 438 for (size_t i = 0; i < arraysize(adjust_cases); i++) { | 455 for (size_t i = 0; i < arraysize(adjust_cases); i++) { |
| 439 size_t offset = adjust_cases[i].input_offset; | 456 size_t offset = adjust_cases[i].input_offset; |
| 440 base::OffsetAdjuster::Adjustments adjustments; | 457 base::OffsetAdjuster::Adjustments adjustments; |
| 441 UnescapeAndDecodeUTF8URLComponentWithAdjustments( | 458 UnescapeAndDecodeUTF8URLComponentWithAdjustments( |
| 442 adjust_cases[i].input, UnescapeRule::NORMAL, &adjustments); | 459 adjust_cases[i].input, UnescapeRule::NORMAL, &adjustments); |
| 443 base::OffsetAdjuster::AdjustOffset(adjustments, &offset); | 460 base::OffsetAdjuster::AdjustOffset(adjustments, &offset); |
| 444 EXPECT_EQ(adjust_cases[i].output_offset, offset) | 461 EXPECT_EQ(adjust_cases[i].output_offset, offset) |
| 445 << "input=" << adjust_cases[i].input | 462 << "input=" << adjust_cases[i].input |
| 446 << " offset=" << adjust_cases[i].input_offset; | 463 << " offset=" << adjust_cases[i].input_offset; |
| 447 } | 464 } |
| 448 } | 465 } |
| 449 | 466 |
| 450 TEST(EscapeTest, EscapeForHTML) { | 467 TEST(EscapeTest, EscapeForHTML) { |
| 451 const EscapeForHTMLCase tests[] = { | 468 const EscapeForHTMLCase tests[] = { |
| 452 { "hello", "hello" }, | 469 {"hello", "hello"}, |
| 453 { "<hello>", "<hello>" }, | 470 {"<hello>", "<hello>"}, |
| 454 { "don\'t mess with me", "don't mess with me" }, | 471 {"don\'t mess with me", "don't mess with me"}, |
| 455 }; | 472 }; |
| 456 for (size_t i = 0; i < arraysize(tests); ++i) { | 473 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 457 std::string result = EscapeForHTML(std::string(tests[i].input)); | 474 std::string result = EscapeForHTML(std::string(tests[i].input)); |
| 458 EXPECT_EQ(std::string(tests[i].expected_output), result); | 475 EXPECT_EQ(std::string(tests[i].expected_output), result); |
| 459 } | 476 } |
| 460 } | 477 } |
| 461 | 478 |
| 462 TEST(EscapeTest, UnescapeForHTML) { | 479 TEST(EscapeTest, UnescapeForHTML) { |
| 463 const EscapeForHTMLCase tests[] = { | 480 const EscapeForHTMLCase tests[] = { |
| 464 { "", "" }, | 481 {"", ""}, |
| 465 { "<hello>", "<hello>" }, | 482 {"<hello>", "<hello>"}, |
| 466 { "don't mess with me", "don\'t mess with me" }, | 483 {"don't mess with me", "don\'t mess with me"}, |
| 467 { "<>&"'", "<>&\"'" }, | 484 {"<>&"'", "<>&\"'"}, |
| 468 { "& lt; & ; &; '", "& lt; & ; &; '" }, | 485 {"& lt; & ; &; '", "& lt; & ; &; '"}, |
| 469 { "&", "&" }, | 486 {"&", "&"}, |
| 470 { """, "\"" }, | 487 {""", "\""}, |
| 471 { "'", "'" }, | 488 {"'", "'"}, |
| 472 { "<", "<" }, | 489 {"<", "<"}, |
| 473 { ">", ">" }, | 490 {">", ">"}, |
| 474 { "& &", "& &" }, | 491 {"& &", "& &"}, |
| 475 }; | 492 }; |
| 476 for (size_t i = 0; i < arraysize(tests); ++i) { | 493 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 477 base::string16 result = UnescapeForHTML(base::ASCIIToUTF16(tests[i].input)); | 494 base::string16 result = UnescapeForHTML(base::ASCIIToUTF16(tests[i].input)); |
| 478 EXPECT_EQ(base::ASCIIToUTF16(tests[i].expected_output), result); | 495 EXPECT_EQ(base::ASCIIToUTF16(tests[i].expected_output), result); |
| 479 } | 496 } |
| 480 } | 497 } |
| 481 | 498 |
| 482 TEST(EscapeTest, EscapeExternalHandlerValue) { | 499 TEST(EscapeTest, EscapeExternalHandlerValue) { |
| 483 ASSERT_EQ( | 500 ASSERT_EQ( |
| 484 // Escaped | 501 // Escaped |
| (...skipping 27 matching lines...) Expand all Loading... |
| 512 "http://example.com/path/sub?q=a|b|c&q=1|2|3#ref|")); | 529 "http://example.com/path/sub?q=a|b|c&q=1|2|3#ref|")); |
| 513 ASSERT_EQ("http://example.com/path/sub?q=a%7Cb%7Cc&q=1%7C2%7C3#ref%7C", | 530 ASSERT_EQ("http://example.com/path/sub?q=a%7Cb%7Cc&q=1%7C2%7C3#ref%7C", |
| 514 EscapeExternalHandlerValue( | 531 EscapeExternalHandlerValue( |
| 515 "http://example.com/path/sub?q=a%7Cb%7Cc&q=1%7C2%7C3#ref%7C")); | 532 "http://example.com/path/sub?q=a%7Cb%7Cc&q=1%7C2%7C3#ref%7C")); |
| 516 ASSERT_EQ("http://[2001:db8:0:1]:80", | 533 ASSERT_EQ("http://[2001:db8:0:1]:80", |
| 517 EscapeExternalHandlerValue("http://[2001:db8:0:1]:80")); | 534 EscapeExternalHandlerValue("http://[2001:db8:0:1]:80")); |
| 518 } | 535 } |
| 519 | 536 |
| 520 } // namespace | 537 } // namespace |
| 521 } // namespace net | 538 } // namespace net |
| OLD | NEW |