| OLD | NEW |
| 1 // Copyright 2007, Google Inc. | 1 // Copyright 2007, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 const char* port; | 92 const char* port; |
| 93 const char* path; | 93 const char* path; |
| 94 const char* query; | 94 const char* query; |
| 95 const char* ref; | 95 const char* ref; |
| 96 const char* expected; | 96 const char* expected; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 // Wrapper around a UConverter object that managers creation and destruction. | 99 // Wrapper around a UConverter object that managers creation and destruction. |
| 100 class UConvScoper { | 100 class UConvScoper { |
| 101 public: | 101 public: |
| 102 UConvScoper(const char* charset_name) { | 102 explicit UConvScoper(const char* charset_name) { |
| 103 UErrorCode err = U_ZERO_ERROR; | 103 UErrorCode err = U_ZERO_ERROR; |
| 104 converter_ = ucnv_open(charset_name, &err); | 104 converter_ = ucnv_open(charset_name, &err); |
| 105 } | 105 } |
| 106 | 106 |
| 107 ~UConvScoper() { | 107 ~UConvScoper() { |
| 108 if (converter_) | 108 if (converter_) |
| 109 ucnv_close(converter_); | 109 ucnv_close(converter_); |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Returns the converter object, may be NULL. | 112 // Returns the converter object, may be NULL. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // Non-BMP UTF-8. | 231 // Non-BMP UTF-8. |
| 232 {L"!\xd800\xdf00!", "utf-8", "!\xf0\x90\x8c\x80!"}, | 232 {L"!\xd800\xdf00!", "utf-8", "!\xf0\x90\x8c\x80!"}, |
| 233 // Big5 | 233 // Big5 |
| 234 {L"\x4f60\x597d", "big5", "\xa7\x41\xa6\x6e"}, | 234 {L"\x4f60\x597d", "big5", "\xa7\x41\xa6\x6e"}, |
| 235 // Unrepresentable character in the destination set. | 235 // Unrepresentable character in the destination set. |
| 236 {L"hello\x4f60\x06de\x597dworld", "big5", "hello\xa7\x41%26%231758%3B\xa6\x6
eworld"}, | 236 {L"hello\x4f60\x06de\x597dworld", "big5", "hello\xa7\x41%26%231758%3B\xa6\x6
eworld"}, |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 for (size_t i = 0; i < ARRAYSIZE(icu_cases); i++) { | 239 for (size_t i = 0; i < ARRAYSIZE(icu_cases); i++) { |
| 240 UConvScoper conv(icu_cases[i].encoding); | 240 UConvScoper conv(icu_cases[i].encoding); |
| 241 ASSERT_TRUE(conv.converter()); | 241 ASSERT_TRUE(conv.converter() != NULL); |
| 242 url_canon::ICUCharsetConverter converter(conv.converter()); | 242 url_canon::ICUCharsetConverter converter(conv.converter()); |
| 243 | 243 |
| 244 std::string str; | 244 std::string str; |
| 245 url_canon::StdStringCanonOutput output(&str); | 245 url_canon::StdStringCanonOutput output(&str); |
| 246 | 246 |
| 247 string16 input_str(WStringToUTF16(icu_cases[i].input)); | 247 string16 input_str(WStringToUTF16(icu_cases[i].input)); |
| 248 int input_len = static_cast<int>(input_str.length()); | 248 int input_len = static_cast<int>(input_str.length()); |
| 249 converter.ConvertFromUTF16(input_str.c_str(), input_len, &output); | 249 converter.ConvertFromUTF16(input_str.c_str(), input_len, &output); |
| 250 output.Complete(); | 250 output.Complete(); |
| 251 | 251 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 {"%3g%78%63%30%2e%30%32%35%30%2E.01", L"%3g%78%63%30%2e%30%32%35%30%2E.01",
"%253gxc0.0250..01", url_parse::Component(0, 17), CanonHostInfo::BROKEN, -1}, | 391 {"%3g%78%63%30%2e%30%32%35%30%2E.01", L"%3g%78%63%30%2e%30%32%35%30%2E.01",
"%253gxc0.0250..01", url_parse::Component(0, 17), CanonHostInfo::BROKEN, -1}, |
| 392 // Something that isn't exactly an IP should get treated as a host and | 392 // Something that isn't exactly an IP should get treated as a host and |
| 393 // spaces escaped. | 393 // spaces escaped. |
| 394 {"192.168.0.1 hello", L"192.168.0.1 hello", "192.168.0.1%20hello", url_parse
::Component(0, 19), CanonHostInfo::NEUTRAL, -1}, | 394 {"192.168.0.1 hello", L"192.168.0.1 hello", "192.168.0.1%20hello", url_parse
::Component(0, 19), CanonHostInfo::NEUTRAL, -1}, |
| 395 // Fullwidth and escaped UTF-8 fullwidth should still be treated as IP. | 395 // Fullwidth and escaped UTF-8 fullwidth should still be treated as IP. |
| 396 // These are "0Xc0.0250.01" in fullwidth. | 396 // These are "0Xc0.0250.01" in fullwidth. |
| 397 {"\xef\xbc\x90%Ef%bc\xb8%ef%Bd%83\xef\xbc\x90%EF%BC%8E\xef\xbc\x90\xef\xbc\x
92\xef\xbc\x95\xef\xbc\x90\xef\xbc%8E\xef\xbc\x90\xef\xbc\x91", L"\xff10\xff38\x
ff43\xff10\xff0e\xff10\xff12\xff15\xff10\xff0e\xff10\xff11", "192.168.0.1", url_
parse::Component(0, 11), CanonHostInfo::IPV4, 3}, | 397 {"\xef\xbc\x90%Ef%bc\xb8%ef%Bd%83\xef\xbc\x90%EF%BC%8E\xef\xbc\x90\xef\xbc\x
92\xef\xbc\x95\xef\xbc\x90\xef\xbc%8E\xef\xbc\x90\xef\xbc\x91", L"\xff10\xff38\x
ff43\xff10\xff0e\xff10\xff12\xff15\xff10\xff0e\xff10\xff11", "192.168.0.1", url_
parse::Component(0, 11), CanonHostInfo::IPV4, 3}, |
| 398 // Broken IP addresses get marked as such. | 398 // Broken IP addresses get marked as such. |
| 399 {"192.168.0.257", L"192.168.0.257", "192.168.0.257", url_parse::Component(0,
13), CanonHostInfo::BROKEN, -1}, | 399 {"192.168.0.257", L"192.168.0.257", "192.168.0.257", url_parse::Component(0,
13), CanonHostInfo::BROKEN, -1}, |
| 400 {"[google.com]", L"[google.com]", "[google.com]", url_parse::Component(0, 12
), CanonHostInfo::BROKEN, -1}, | 400 {"[google.com]", L"[google.com]", "[google.com]", url_parse::Component(0, 12
), CanonHostInfo::BROKEN, -1}, |
| 401 // Cyrillic letter followed buy ( should return punicode for ( escaped bef
ore punicode string was created. I.e. |
| 402 // if ( is escaped after punicode is created we would get xn--%28-8tb (inc
orrect). |
| 403 {"\xd1\x82(", L"\x0442(", "xn--%28-7ed", url_parse::Component(0, 11), CanonH
ostInfo::NEUTRAL, -1}, |
| 401 }; | 404 }; |
| 402 | 405 |
| 403 // CanonicalizeHost() non-verbose. | 406 // CanonicalizeHost() non-verbose. |
| 404 std::string out_str; | 407 std::string out_str; |
| 405 for (size_t i = 0; i < arraysize(host_cases); i++) { | 408 for (size_t i = 0; i < arraysize(host_cases); i++) { |
| 406 // Narrow version. | 409 // Narrow version. |
| 407 if (host_cases[i].input8) { | 410 if (host_cases[i].input8) { |
| 408 int host_len = static_cast<int>(strlen(host_cases[i].input8)); | 411 int host_len = static_cast<int>(strlen(host_cases[i].input8)); |
| 409 url_parse::Component in_comp(0, host_len); | 412 url_parse::Component in_comp(0, host_len); |
| 410 url_parse::Component out_comp; | 413 url_parse::Component out_comp; |
| (...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1910 url_canon::StdStringCanonOutput repl_output(&repl_str); | 1913 url_canon::StdStringCanonOutput repl_output(&repl_str); |
| 1911 url_canon::ReplaceFileURL(src, parsed, repl, NULL, &repl_output, &repl_parsed)
; | 1914 url_canon::ReplaceFileURL(src, parsed, repl, NULL, &repl_output, &repl_parsed)
; |
| 1912 repl_output.Complete(); | 1915 repl_output.Complete(); |
| 1913 | 1916 |
| 1914 // Generate the expected string and check. | 1917 // Generate the expected string and check. |
| 1915 std::string expected("file:///foo?"); | 1918 std::string expected("file:///foo?"); |
| 1916 for (size_t i = 0; i < new_query.length(); i++) | 1919 for (size_t i = 0; i < new_query.length(); i++) |
| 1917 expected.push_back('a'); | 1920 expected.push_back('a'); |
| 1918 EXPECT_TRUE(expected == repl_str); | 1921 EXPECT_TRUE(expected == repl_str); |
| 1919 } | 1922 } |
| OLD | NEW |