OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/net_util.h" | 5 #include "net/base/net_util.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 false, false, false, false, false, | 324 false, false, false, false, false, |
325 false, false, false, false, false, | 325 false, false, false, false, false, |
326 false, false, false, false, false, | 326 false, false, false, false, false, |
327 }}, | 327 }}, |
328 {"google.xn--comevil-v04f.jp", L"google.com\x30ce" L"evil.jp", | 328 {"google.xn--comevil-v04f.jp", L"google.com\x30ce" L"evil.jp", |
329 {false, false, false, false, false, | 329 {false, false, false, false, false, |
330 false, false, false, false, false, | 330 false, false, false, false, false, |
331 false, false, false, false, false, | 331 false, false, false, false, false, |
332 false, false, false, false, false, | 332 false, false, false, false, false, |
333 }}, | 333 }}, |
334 // Padlock icon spoof. | |
335 {"xn--google-hj64e", L"\U0001f512google.com", | |
336 {false, false, false, false, false, | |
337 false, false, false, false, false, | |
338 false, false, false, false, false, | |
339 false, false, false, false, false, | |
340 }}, | |
341 // Ensure that by blacklisting "\xd83d\xdd12", we have not inadvertently | |
342 // blacklisted all strings with the surrogate '\xdd12'. | |
mmenke
2015/06/05 15:08:06
nit: Don't use "we" in comments
Matt Giuca
2015/06/09 04:10:35
Hmm, not a fan of this rule (it means rewriting ac
| |
343 {"xn--fk9c.com", L"\U00010912.com", | |
344 {true, false, false, false, false, | |
345 false, false, false, false, false, | |
346 false, false, false, false, false, | |
347 false, false, false, false, false, | |
348 }}, | |
334 #if 0 | 349 #if 0 |
335 // These two cases are special. We need a separate test. | 350 // These two cases are special. We need a separate test. |
336 // U+3000 and U+3002 are normalized to ASCII space and dot. | 351 // U+3000 and U+3002 are normalized to ASCII space and dot. |
337 {"xn-- -kq6ay5z.cn", L"\x4e2d\x56fd\x3000.cn", | 352 {"xn-- -kq6ay5z.cn", L"\x4e2d\x56fd\x3000.cn", |
338 {false, false, true, false, false, | 353 {false, false, true, false, false, |
339 false, false, false, false, false, | 354 false, false, false, false, false, |
340 false, false, false, false, false, | 355 false, false, false, false, false, |
341 false, false, true, false, false, | 356 false, false, true, false, false, |
342 true}}, | 357 true}}, |
343 {"xn--fiqs8s.cn", L"\x4e2d\x56fd\x3002" L"cn", | 358 {"xn--fiqs8s.cn", L"\x4e2d\x56fd\x3002" L"cn", |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 for (size_t i = 0; i < arraysize(idn_cases); i++) { | 430 for (size_t i = 0; i < arraysize(idn_cases); i++) { |
416 for (size_t j = 0; j < arraysize(kLanguages); j++) { | 431 for (size_t j = 0; j < arraysize(kLanguages); j++) { |
417 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow | 432 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow |
418 if (j == 3 || j == 17 || j == 18) | 433 if (j == 3 || j == 17 || j == 18) |
419 continue; | 434 continue; |
420 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j])); | 435 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j])); |
421 base::string16 expected(idn_cases[i].unicode_allowed[j] ? | 436 base::string16 expected(idn_cases[i].unicode_allowed[j] ? |
422 WideToUTF16(idn_cases[i].unicode_output) : | 437 WideToUTF16(idn_cases[i].unicode_output) : |
423 ASCIIToUTF16(idn_cases[i].input)); | 438 ASCIIToUTF16(idn_cases[i].input)); |
424 AppendLanguagesToOutputs(kLanguages[j], &expected, &output); | 439 AppendLanguagesToOutputs(kLanguages[j], &expected, &output); |
425 EXPECT_EQ(expected, output); | 440 EXPECT_EQ(expected, output) << "input: \"" << idn_cases[i].input |
441 << "\", languages: \"" << kLanguages[j] | |
442 << "\""; | |
426 } | 443 } |
427 } | 444 } |
428 } | 445 } |
429 | 446 |
430 TEST(NetUtilTest, IDNToUnicodeSlow) { | 447 TEST(NetUtilTest, IDNToUnicodeSlow) { |
431 for (size_t i = 0; i < arraysize(idn_cases); i++) { | 448 for (size_t i = 0; i < arraysize(idn_cases); i++) { |
432 for (size_t j = 0; j < arraysize(kLanguages); j++) { | 449 for (size_t j = 0; j < arraysize(kLanguages); j++) { |
433 // !(ja || zh-TW,en || ko,ja) -> IDNToUnicodeFast | 450 // !(ja || zh-TW,en || ko,ja) -> IDNToUnicodeFast |
434 if (!(j == 3 || j == 17 || j == 18)) | 451 if (!(j == 3 || j == 17 || j == 18)) |
435 continue; | 452 continue; |
436 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j])); | 453 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j])); |
437 base::string16 expected(idn_cases[i].unicode_allowed[j] ? | 454 base::string16 expected(idn_cases[i].unicode_allowed[j] ? |
438 WideToUTF16(idn_cases[i].unicode_output) : | 455 WideToUTF16(idn_cases[i].unicode_output) : |
439 ASCIIToUTF16(idn_cases[i].input)); | 456 ASCIIToUTF16(idn_cases[i].input)); |
440 AppendLanguagesToOutputs(kLanguages[j], &expected, &output); | 457 AppendLanguagesToOutputs(kLanguages[j], &expected, &output); |
441 EXPECT_EQ(expected, output); | 458 EXPECT_EQ(expected, output) << "input: \"" << idn_cases[i].input |
459 << "\", languages: \"" << kLanguages[j] | |
460 << "\""; | |
442 } | 461 } |
443 } | 462 } |
444 } | 463 } |
445 | 464 |
446 // ulocdata_getExemplarSet may fail with some locales (currently bn, gu, and | 465 // ulocdata_getExemplarSet may fail with some locales (currently bn, gu, and |
447 // te), which was causing a crash (See http://crbug.com/510551). This may be an | 466 // te), which was causing a crash (See http://crbug.com/510551). This may be an |
448 // icu bug, but regardless, that should not cause a crash. | 467 // icu bug, but regardless, that should not cause a crash. |
449 TEST(NetUtilTest, IDNToUnicodeNeverCrashes) { | 468 TEST(NetUtilTest, IDNToUnicodeNeverCrashes) { |
450 for (char c1 = 'a'; c1 <= 'z'; c1++) { | 469 for (char c1 = 'a'; c1 <= 'z'; c1++) { |
451 for (char c2 = 'a'; c2 <= 'z'; c2++) { | 470 for (char c2 = 'a'; c2 <= 'z'; c2++) { |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1075 | 1094 |
1076 const size_t omit_all_offsets[] = { | 1095 const size_t omit_all_offsets[] = { |
1077 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, | 1096 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, |
1078 0, 1, 2, 3, 4, 5, 6, 7 | 1097 0, 1, 2, 3, 4, 5, 6, 7 |
1079 }; | 1098 }; |
1080 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll, | 1099 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll, |
1081 UnescapeRule::NORMAL, omit_all_offsets); | 1100 UnescapeRule::NORMAL, omit_all_offsets); |
1082 } | 1101 } |
1083 | 1102 |
1084 } // namespace net | 1103 } // namespace net |
OLD | NEW |