Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: net/base/escape_unittest.cc

Issue 1704163003: FileURLToFilePath: Don't unescape '/' and '\\'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add constant, fix spelling, add test, remove smewhat tangential test added earlier Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 "%7B%7C%7D~%7F%80%FF"); 143 "%7B%7C%7D~%7F%80%FF");
144 } 144 }
145 145
146 TEST(EscapeTest, EscapeUrlEncodedDataSpace) { 146 TEST(EscapeTest, EscapeUrlEncodedDataSpace) {
147 ASSERT_EQ(EscapeUrlEncodedData("a b", true), "a+b"); 147 ASSERT_EQ(EscapeUrlEncodedData("a b", true), "a+b");
148 ASSERT_EQ(EscapeUrlEncodedData("a b", false), "a%20b"); 148 ASSERT_EQ(EscapeUrlEncodedData("a b", false), "a%20b");
149 } 149 }
150 150
151 TEST(EscapeTest, UnescapeURLComponentASCII) { 151 TEST(EscapeTest, UnescapeURLComponentASCII) {
152 const UnescapeURLCaseASCII unescape_cases[] = { 152 const UnescapeURLCaseASCII unescape_cases[] = {
153 {"", UnescapeRule::NORMAL, ""}, 153 {"", UnescapeRule::NORMAL, ""},
154 {"%2", UnescapeRule::NORMAL, "%2"}, 154 {"%2", UnescapeRule::NORMAL, "%2"},
155 {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"}, 155 {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"},
156 {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"}, 156 {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"},
157 {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"}, 157 {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"},
158 {"Some%20random text %25%2dOK", UnescapeRule::NONE, 158 {"Some%20random text %25%2dOK", UnescapeRule::NONE,
159 "Some%20random text %25%2dOK"}, 159 "Some%20random text %25%2dOK"},
160 {"Some%20random text %25%2dOK", UnescapeRule::NORMAL, 160 {"Some%20random text %25%2dOK", UnescapeRule::NORMAL,
161 "Some%20random text %25-OK"}, 161 "Some%20random text %25-OK"},
162 {"Some%20random text %25%2dOK", UnescapeRule::SPACES, 162 {"Some%20random text %25%2dOK", UnescapeRule::SPACES,
163 "Some random text %25-OK"}, 163 "Some random text %25-OK"},
164 {"Some%20random text %25%2dOK", UnescapeRule::URL_SPECIAL_CHARS, 164 {"Some%20random text %25%2dOK", UnescapeRule::PATH_SEPARATORS,
165 "Some%20random text %-OK"}, 165 "Some%20random text %25-OK"},
mmenke 2016/02/19 17:55:12 Sorry for the reformatting - it was due to git cl
166 {"Some%20random text %25%2dOK", 166 {"Some%20random text %25%2dOK",
167 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS, 167 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS,
168 "Some random text %-OK"}, 168 "Some%20random text %-OK"},
169 {"%A0%B1%C2%D3%E4%F5", UnescapeRule::NORMAL, "\xA0\xB1\xC2\xD3\xE4\xF5"}, 169 {"Some%20random text %25%2dOK",
170 {"%Aa%Bb%Cc%Dd%Ee%Ff", UnescapeRule::NORMAL, "\xAa\xBb\xCc\xDd\xEe\xFf"}, 170 UnescapeRule::SPACES |
171 // Certain URL-sensitive characters should not be unescaped unless asked. 171 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS,
172 {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", UnescapeRule::SPACES, 172 "Some random text %-OK"},
173 "Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"}, 173 {"%A0%B1%C2%D3%E4%F5", UnescapeRule::NORMAL, "\xA0\xB1\xC2\xD3\xE4\xF5"},
174 {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", 174 {"%Aa%Bb%Cc%Dd%Ee%Ff", UnescapeRule::NORMAL, "\xAa\xBb\xCc\xDd\xEe\xFf"},
175 UnescapeRule::URL_SPECIAL_CHARS, 175 // Certain URL-sensitive characters should not be unescaped unless asked.
176 "Hello%20%13%10world ## ?? == && %% ++"}, 176 {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+",
177 // We can neither escape nor unescape '@' since some websites expect it to 177 UnescapeRule::SPACES, "Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"},
178 // be preserved as either '@' or "%40". 178 {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+",
179 // See http://b/996720 and http://crbug.com/23933 . 179 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS,
180 {"me@my%40example", UnescapeRule::NORMAL, "me@my%40example"}, 180 "Hello%20%13%10world ## ?? == && %% ++"},
181 // Control characters. 181 // We can neither escape nor unescape '@' since some websites expect it to
182 {"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::URL_SPECIAL_CHARS, 182 // be preserved as either '@' or "%40".
183 "%01%02%03%04%05%06%07%08%09 %"}, 183 // See http://b/996720 and http://crbug.com/23933 .
184 {"%01%02%03%04%05%06%07%08%09 %25", 184 {"me@my%40example", UnescapeRule::NORMAL, "me@my%40example"},
185 UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 185 // Control characters.
186 "\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"}, 186 {"%01%02%03%04%05%06%07%08%09 %25",
187 {"Hello%20%13%10%02", UnescapeRule::SPACES, "Hello %13%10%02"}, 187 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS,
188 {"Hello%20%13%10%02", UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 188 "%01%02%03%04%05%06%07%08%09 %"},
189 "Hello%20\x13\x10\x02"}, 189 {"%01%02%03%04%05%06%07%08%09 %25",
190 UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
191 "\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"},
192 {"Hello%20%13%10%02", UnescapeRule::SPACES, "Hello %13%10%02"},
193 {"Hello%20%13%10%02", UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
194 "Hello%20\x13\x10\x02"},
195
196 // '/' and '\\' should only be unescaped by PATH_SEPARATORS.
197 {"%2F%5C", UnescapeRule::PATH_SEPARATORS, "/\\"},
198 {"%2F%5C", UnescapeRule::SPACES |
199 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS |
200 UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
201 "%2F%5C"},
190 }; 202 };
191 203
192 for (size_t i = 0; i < arraysize(unescape_cases); i++) { 204 for (size_t i = 0; i < arraysize(unescape_cases); i++) {
193 std::string str(unescape_cases[i].input); 205 std::string str(unescape_cases[i].input);
194 EXPECT_EQ(std::string(unescape_cases[i].output), 206 EXPECT_EQ(std::string(unescape_cases[i].output),
195 UnescapeURLComponent(str, unescape_cases[i].rules)); 207 UnescapeURLComponent(str, unescape_cases[i].rules));
196 } 208 }
197 209
198 // Test the NULL character unescaping (which wouldn't work above since those 210 // Test the NULL character unescaping (which wouldn't work above since those
199 // are just char pointers). 211 // are just char pointers).
(...skipping 11 matching lines...) Expand all
211 223
212 // When we're not unescaping NULLs. 224 // When we're not unescaping NULLs.
213 expected = "Null"; 225 expected = "Null";
214 expected.push_back(0); 226 expected.push_back(0);
215 expected.append("%009Test"); 227 expected.append("%009Test");
216 EXPECT_EQ(expected, UnescapeURLComponent(input, UnescapeRule::NORMAL)); 228 EXPECT_EQ(expected, UnescapeURLComponent(input, UnescapeRule::NORMAL));
217 } 229 }
218 230
219 TEST(EscapeTest, UnescapeURLComponent) { 231 TEST(EscapeTest, UnescapeURLComponent) {
220 const UnescapeURLCase unescape_cases[] = { 232 const UnescapeURLCase unescape_cases[] = {
221 {L"", UnescapeRule::NORMAL, L""}, 233 {L"", UnescapeRule::NORMAL, L""},
222 {L"%2", UnescapeRule::NORMAL, L"%2"}, 234 {L"%2", UnescapeRule::NORMAL, L"%2"},
223 {L"%%%%%%", UnescapeRule::NORMAL, L"%%%%%%"}, 235 {L"%%%%%%", UnescapeRule::NORMAL, L"%%%%%%"},
224 {L"Don't escape anything", UnescapeRule::NORMAL, L"Don't escape anything"}, 236 {L"Don't escape anything", UnescapeRule::NORMAL,
225 {L"Invalid %escape %2", UnescapeRule::NORMAL, L"Invalid %escape %2"}, 237 L"Don't escape anything"},
226 {L"Some%20random text %25%2dOK", UnescapeRule::NONE, 238 {L"Invalid %escape %2", UnescapeRule::NORMAL, L"Invalid %escape %2"},
227 L"Some%20random text %25%2dOK"}, 239 {L"Some%20random text %25%2dOK", UnescapeRule::NONE,
228 {L"Some%20random text %25%2dOK", UnescapeRule::NORMAL, 240 L"Some%20random text %25%2dOK"},
229 L"Some%20random text %25-OK"}, 241 {L"Some%20random text %25%2dOK", UnescapeRule::NORMAL,
230 {L"Some%20random text %25%E2%80", UnescapeRule::NORMAL, 242 L"Some%20random text %25-OK"},
231 L"Some%20random text %25\xE2\x80"}, 243 {L"Some%20random text %25%E2%80", UnescapeRule::NORMAL,
232 {L"Some%20random text %25%E2%80OK", UnescapeRule::NORMAL, 244 L"Some%20random text %25\xE2\x80"},
233 L"Some%20random text %25\xE2\x80OK"}, 245 {L"Some%20random text %25%E2%80OK", UnescapeRule::NORMAL,
234 {L"Some%20random text %25%E2%80%84OK", UnescapeRule::NORMAL, 246 L"Some%20random text %25\xE2\x80OK"},
235 L"Some%20random text %25\xE2\x80\x84OK"}, 247 {L"Some%20random text %25%E2%80%84OK", UnescapeRule::NORMAL,
248 L"Some%20random text %25\xE2\x80\x84OK"},
236 249
237 // BiDi Control characters should not be unescaped unless explicity told to 250 // BiDi Control characters should not be unescaped unless explicity told
238 // do so with UnescapeRule::SPOOFING_AND_CONTROL_CHARS 251 // to
239 {L"Some%20random text %25%D8%9COK", UnescapeRule::NORMAL, 252 // do so with UnescapeRule::SPOOFING_AND_CONTROL_CHARS
240 L"Some%20random text %25%D8%9COK"}, 253 {L"Some%20random text %25%D8%9COK", UnescapeRule::NORMAL,
241 {L"Some%20random text %25%E2%80%8EOK", UnescapeRule::NORMAL, 254 L"Some%20random text %25%D8%9COK"},
242 L"Some%20random text %25%E2%80%8EOK"}, 255 {L"Some%20random text %25%E2%80%8EOK", UnescapeRule::NORMAL,
243 {L"Some%20random text %25%E2%80%8FOK", UnescapeRule::NORMAL, 256 L"Some%20random text %25%E2%80%8EOK"},
244 L"Some%20random text %25%E2%80%8FOK"}, 257 {L"Some%20random text %25%E2%80%8FOK", UnescapeRule::NORMAL,
245 {L"Some%20random text %25%E2%80%AAOK", UnescapeRule::NORMAL, 258 L"Some%20random text %25%E2%80%8FOK"},
246 L"Some%20random text %25%E2%80%AAOK"}, 259 {L"Some%20random text %25%E2%80%AAOK", UnescapeRule::NORMAL,
247 {L"Some%20random text %25%E2%80%ABOK", UnescapeRule::NORMAL, 260 L"Some%20random text %25%E2%80%AAOK"},
248 L"Some%20random text %25%E2%80%ABOK"}, 261 {L"Some%20random text %25%E2%80%ABOK", UnescapeRule::NORMAL,
249 {L"Some%20random text %25%E2%80%AEOK", UnescapeRule::NORMAL, 262 L"Some%20random text %25%E2%80%ABOK"},
250 L"Some%20random text %25%E2%80%AEOK"}, 263 {L"Some%20random text %25%E2%80%AEOK", UnescapeRule::NORMAL,
251 {L"Some%20random text %25%E2%81%A6OK", UnescapeRule::NORMAL, 264 L"Some%20random text %25%E2%80%AEOK"},
252 L"Some%20random text %25%E2%81%A6OK"}, 265 {L"Some%20random text %25%E2%81%A6OK", UnescapeRule::NORMAL,
253 {L"Some%20random text %25%E2%81%A9OK", UnescapeRule::NORMAL, 266 L"Some%20random text %25%E2%81%A6OK"},
254 L"Some%20random text %25%E2%81%A9OK"}, 267 {L"Some%20random text %25%E2%81%A9OK", UnescapeRule::NORMAL,
255 // UnescapeRule::SPOOFING_AND_CONTROL_CHARS should unescape BiDi Control 268 L"Some%20random text %25%E2%81%A9OK"},
256 // characters. 269 // UnescapeRule::SPOOFING_AND_CONTROL_CHARS should unescape BiDi Control
257 {L"Some%20random text %25%D8%9COK", 270 // characters.
258 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 271 {L"Some%20random text %25%D8%9COK",
259 L"Some%20random text %25\xD8\x9COK"}, 272 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
260 {L"Some%20random text %25%E2%80%8EOK", 273 L"Some%20random text %25\xD8\x9COK"},
261 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 274 {L"Some%20random text %25%E2%80%8EOK",
262 L"Some%20random text %25\xE2\x80\x8EOK"}, 275 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
263 {L"Some%20random text %25%E2%80%8FOK", 276 L"Some%20random text %25\xE2\x80\x8EOK"},
264 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 277 {L"Some%20random text %25%E2%80%8FOK",
265 L"Some%20random text %25\xE2\x80\x8FOK"}, 278 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
266 {L"Some%20random text %25%E2%80%AAOK", 279 L"Some%20random text %25\xE2\x80\x8FOK"},
267 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 280 {L"Some%20random text %25%E2%80%AAOK",
268 L"Some%20random text %25\xE2\x80\xAAOK"}, 281 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
269 {L"Some%20random text %25%E2%80%ABOK", 282 L"Some%20random text %25\xE2\x80\xAAOK"},
270 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 283 {L"Some%20random text %25%E2%80%ABOK",
271 L"Some%20random text %25\xE2\x80\xABOK"}, 284 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
272 {L"Some%20random text %25%E2%80%AEOK", 285 L"Some%20random text %25\xE2\x80\xABOK"},
273 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 286 {L"Some%20random text %25%E2%80%AEOK",
274 L"Some%20random text %25\xE2\x80\xAEOK"}, 287 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
275 {L"Some%20random text %25%E2%81%A6OK", 288 L"Some%20random text %25\xE2\x80\xAEOK"},
276 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 289 {L"Some%20random text %25%E2%81%A6OK",
277 L"Some%20random text %25\xE2\x81\xA6OK"}, 290 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
278 {L"Some%20random text %25%E2%81%A9OK", 291 L"Some%20random text %25\xE2\x81\xA6OK"},
279 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 292 {L"Some%20random text %25%E2%81%A9OK",
280 L"Some%20random text %25\xE2\x81\xA9OK"}, 293 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
294 L"Some%20random text %25\xE2\x81\xA9OK"},
281 295
282 // Certain banned characters should not be unescaped unless explicitly told 296 // Certain banned characters should not be unescaped unless explicitly
283 // to do so with UnescapeRule::SPOOFING_AND_CONTROL_CHARS. 297 // told
284 // U+1F50F LOCK WITH INK PEN 298 // to do so with UnescapeRule::SPOOFING_AND_CONTROL_CHARS.
285 {L"Some%20random text %25%F0%9F%94%8FOK", UnescapeRule::NORMAL, 299 // U+1F50F LOCK WITH INK PEN
286 L"Some%20random text %25%F0%9F%94%8FOK"}, 300 {L"Some%20random text %25%F0%9F%94%8FOK", UnescapeRule::NORMAL,
287 // U+1F510 CLOSED LOCK WITH KEY 301 L"Some%20random text %25%F0%9F%94%8FOK"},
288 {L"Some%20random text %25%F0%9F%94%90OK", UnescapeRule::NORMAL, 302 // U+1F510 CLOSED LOCK WITH KEY
289 L"Some%20random text %25%F0%9F%94%90OK"}, 303 {L"Some%20random text %25%F0%9F%94%90OK", UnescapeRule::NORMAL,
290 // U+1F512 LOCK 304 L"Some%20random text %25%F0%9F%94%90OK"},
291 {L"Some%20random text %25%F0%9F%94%92OK", UnescapeRule::NORMAL, 305 // U+1F512 LOCK
292 L"Some%20random text %25%F0%9F%94%92OK"}, 306 {L"Some%20random text %25%F0%9F%94%92OK", UnescapeRule::NORMAL,
293 // U+1F513 OPEN LOCK 307 L"Some%20random text %25%F0%9F%94%92OK"},
294 {L"Some%20random text %25%F0%9F%94%93OK", UnescapeRule::NORMAL, 308 // U+1F513 OPEN LOCK
295 L"Some%20random text %25%F0%9F%94%93OK"}, 309 {L"Some%20random text %25%F0%9F%94%93OK", UnescapeRule::NORMAL,
296 // UnescapeRule::SPOOFING_AND_CONTROL_CHARS should unescape banned 310 L"Some%20random text %25%F0%9F%94%93OK"},
297 // characters. 311 // UnescapeRule::SPOOFING_AND_CONTROL_CHARS should unescape banned
298 {L"Some%20random text %25%F0%9F%94%8FOK", 312 // characters.
299 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 313 {L"Some%20random text %25%F0%9F%94%8FOK",
300 L"Some%20random text %25\xF0\x9F\x94\x8FOK"}, 314 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
301 {L"Some%20random text %25%F0%9F%94%90OK", 315 L"Some%20random text %25\xF0\x9F\x94\x8FOK"},
302 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 316 {L"Some%20random text %25%F0%9F%94%90OK",
303 L"Some%20random text %25\xF0\x9F\x94\x90OK"}, 317 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
304 {L"Some%20random text %25%F0%9F%94%92OK", 318 L"Some%20random text %25\xF0\x9F\x94\x90OK"},
305 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 319 {L"Some%20random text %25%F0%9F%94%92OK",
306 L"Some%20random text %25\xF0\x9F\x94\x92OK"}, 320 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
307 {L"Some%20random text %25%F0%9F%94%93OK", 321 L"Some%20random text %25\xF0\x9F\x94\x92OK"},
308 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 322 {L"Some%20random text %25%F0%9F%94%93OK",
309 L"Some%20random text %25\xF0\x9F\x94\x93OK"}, 323 UnescapeRule::NORMAL | UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
324 L"Some%20random text %25\xF0\x9F\x94\x93OK"},
310 325
311 {L"Some%20random text %25%2dOK", UnescapeRule::SPACES, 326 {L"Some%20random text %25%2dOK", UnescapeRule::SPACES,
312 L"Some random text %25-OK"}, 327 L"Some random text %25-OK"},
313 {L"Some%20random text %25%2dOK", UnescapeRule::URL_SPECIAL_CHARS, 328 {L"Some%20random text %25%2dOK",
314 L"Some%20random text %-OK"}, 329 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS,
315 {L"Some%20random text %25%2dOK", 330 L"Some%20random text %-OK"},
316 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS, 331 {L"Some%20random text %25%2dOK",
317 L"Some random text %-OK"}, 332 UnescapeRule::SPACES |
318 {L"%A0%B1%C2%D3%E4%F5", UnescapeRule::NORMAL, L"\xA0\xB1\xC2\xD3\xE4\xF5"}, 333 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS,
319 {L"%Aa%Bb%Cc%Dd%Ee%Ff", UnescapeRule::NORMAL, L"\xAa\xBb\xCc\xDd\xEe\xFf"}, 334 L"Some random text %-OK"},
320 // Certain URL-sensitive characters should not be unescaped unless asked. 335 {L"%A0%B1%C2%D3%E4%F5", UnescapeRule::NORMAL,
321 {L"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", UnescapeRule::SPACES, 336 L"\xA0\xB1\xC2\xD3\xE4\xF5"},
322 L"Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"}, 337 {L"%Aa%Bb%Cc%Dd%Ee%Ff", UnescapeRule::NORMAL,
323 {L"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", 338 L"\xAa\xBb\xCc\xDd\xEe\xFf"},
324 UnescapeRule::URL_SPECIAL_CHARS, 339 // Certain URL-sensitive characters should not be unescaped unless asked.
325 L"Hello%20%13%10world ## ?? == && %% ++"}, 340 {L"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+",
326 // We can neither escape nor unescape '@' since some websites expect it to 341 UnescapeRule::SPACES,
327 // be preserved as either '@' or "%40". 342 L"Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"},
328 // See http://b/996720 and http://crbug.com/23933 . 343 {L"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+",
329 {L"me@my%40example", UnescapeRule::NORMAL, L"me@my%40example"}, 344 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS,
330 // Control characters. 345 L"Hello%20%13%10world ## ?? == && %% ++"},
331 {L"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::URL_SPECIAL_CHARS, 346 // We can neither escape nor unescape '@' since some websites expect it to
332 L"%01%02%03%04%05%06%07%08%09 %"}, 347 // be preserved as either '@' or "%40".
333 {L"%01%02%03%04%05%06%07%08%09 %25", 348 // See http://b/996720 and http://crbug.com/23933 .
334 UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 349 {L"me@my%40example", UnescapeRule::NORMAL, L"me@my%40example"},
335 L"\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"}, 350 // Control characters.
336 {L"Hello%20%13%10%02", UnescapeRule::SPACES, L"Hello %13%10%02"}, 351 {L"%01%02%03%04%05%06%07%08%09 %25",
337 {L"Hello%20%13%10%02", UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 352 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS,
338 L"Hello%20\x13\x10\x02"}, 353 L"%01%02%03%04%05%06%07%08%09 %"},
339 {L"Hello\x9824\x9827", UnescapeRule::SPOOFING_AND_CONTROL_CHARS, 354 {L"%01%02%03%04%05%06%07%08%09 %25",
340 L"Hello\x9824\x9827"}, 355 UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
356 L"\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"},
357 {L"Hello%20%13%10%02", UnescapeRule::SPACES, L"Hello %13%10%02"},
358 {L"Hello%20%13%10%02", UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
359 L"Hello%20\x13\x10\x02"},
360 {L"Hello\x9824\x9827", UnescapeRule::SPOOFING_AND_CONTROL_CHARS,
361 L"Hello\x9824\x9827"},
341 }; 362 };
342 363
343 for (size_t i = 0; i < arraysize(unescape_cases); i++) { 364 for (size_t i = 0; i < arraysize(unescape_cases); i++) {
344 base::string16 str(base::WideToUTF16(unescape_cases[i].input)); 365 base::string16 str(base::WideToUTF16(unescape_cases[i].input));
345 EXPECT_EQ(base::WideToUTF16(unescape_cases[i].output), 366 EXPECT_EQ(base::WideToUTF16(unescape_cases[i].output),
346 UnescapeURLComponent(str, unescape_cases[i].rules)); 367 UnescapeURLComponent(str, unescape_cases[i].rules));
347 } 368 }
348 369
349 // Test the NULL character unescaping (which wouldn't work above since those 370 // Test the NULL character unescaping (which wouldn't work above since those
350 // are just char pointers). 371 // are just char pointers).
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 "http://example.com/path/sub?q=a|b|c&q=1|2|3#ref|")); 567 "http://example.com/path/sub?q=a|b|c&q=1|2|3#ref|"));
547 ASSERT_EQ("http://example.com/path/sub?q=a%7Cb%7Cc&q=1%7C2%7C3#ref%7C", 568 ASSERT_EQ("http://example.com/path/sub?q=a%7Cb%7Cc&q=1%7C2%7C3#ref%7C",
548 EscapeExternalHandlerValue( 569 EscapeExternalHandlerValue(
549 "http://example.com/path/sub?q=a%7Cb%7Cc&q=1%7C2%7C3#ref%7C")); 570 "http://example.com/path/sub?q=a%7Cb%7Cc&q=1%7C2%7C3#ref%7C"));
550 ASSERT_EQ("http://[2001:db8:0:1]:80", 571 ASSERT_EQ("http://[2001:db8:0:1]:80",
551 EscapeExternalHandlerValue("http://[2001:db8:0:1]:80")); 572 EscapeExternalHandlerValue("http://[2001:db8:0:1]:80"));
552 } 573 }
553 574
554 } // namespace 575 } // namespace
555 } // namespace net 576 } // namespace net
OLDNEW
« net/base/escape.h ('K') | « net/base/escape.cc ('k') | net/base/filename_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698