| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <errno.h> | 5 #include <errno.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/url_canon.h" | 9 #include "url/url_canon.h" |
| 10 #include "url/url_canon_internal.h" | 10 #include "url/url_canon_internal.h" |
| 11 #include "url/url_canon_stdstring.h" | 11 #include "url/url_canon_stdstring.h" |
| 12 #include "url/url_parse.h" | 12 #include "url/url_parse.h" |
| 13 #include "url/url_test_utils.h" | 13 #include "url/url_test_utils.h" |
| 14 | 14 |
| 15 // Some implementations of base/basictypes.h may define ARRAYSIZE. | |
| 16 // If it's not defined, we define it to the ARRAYSIZE_UNSAFE macro | |
| 17 // which is in our version of basictypes.h. | |
| 18 #ifndef ARRAYSIZE | |
| 19 #define ARRAYSIZE ARRAYSIZE_UNSAFE | |
| 20 #endif | |
| 21 | |
| 22 namespace url { | 15 namespace url { |
| 23 | 16 |
| 24 using test_utils::WStringToUTF16; | 17 using test_utils::WStringToUTF16; |
| 25 using test_utils::ConvertUTF8ToUTF16; | 18 using test_utils::ConvertUTF8ToUTF16; |
| 26 using test_utils::ConvertUTF16ToUTF8; | 19 using test_utils::ConvertUTF16ToUTF8; |
| 27 | 20 |
| 28 namespace { | 21 namespace { |
| 29 | 22 |
| 30 struct ComponentCase { | 23 struct ComponentCase { |
| 31 const char* input; | 24 const char* input; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 const char* output; | 109 const char* output; |
| 117 } utf_cases[] = { | 110 } utf_cases[] = { |
| 118 // Valid code points. | 111 // Valid code points. |
| 119 {0x24, "\x24"}, | 112 {0x24, "\x24"}, |
| 120 {0xA2, "\xC2\xA2"}, | 113 {0xA2, "\xC2\xA2"}, |
| 121 {0x20AC, "\xE2\x82\xAC"}, | 114 {0x20AC, "\xE2\x82\xAC"}, |
| 122 {0x24B62, "\xF0\xA4\xAD\xA2"}, | 115 {0x24B62, "\xF0\xA4\xAD\xA2"}, |
| 123 {0x10FFFF, "\xF4\x8F\xBF\xBF"}, | 116 {0x10FFFF, "\xF4\x8F\xBF\xBF"}, |
| 124 }; | 117 }; |
| 125 std::string out_str; | 118 std::string out_str; |
| 126 for (size_t i = 0; i < ARRAYSIZE(utf_cases); i++) { | 119 for (size_t i = 0; i < arraysize(utf_cases); i++) { |
| 127 out_str.clear(); | 120 out_str.clear(); |
| 128 StdStringCanonOutput output(&out_str); | 121 StdStringCanonOutput output(&out_str); |
| 129 AppendUTF8Value(utf_cases[i].input, &output); | 122 AppendUTF8Value(utf_cases[i].input, &output); |
| 130 output.Complete(); | 123 output.Complete(); |
| 131 EXPECT_EQ(utf_cases[i].output, out_str); | 124 EXPECT_EQ(utf_cases[i].output, out_str); |
| 132 } | 125 } |
| 133 } | 126 } |
| 134 | 127 |
| 135 #if defined(GTEST_HAS_DEATH_TEST) | 128 #if defined(GTEST_HAS_DEATH_TEST) |
| 136 // TODO(mattm): Can't run this in debug mode for now, since the DCHECK will | 129 // TODO(mattm): Can't run this in debug mode for now, since the DCHECK will |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // Character going off the end. | 168 // Character going off the end. |
| 176 {"\xe4\xbd\xa0\xe5\xa5", L"\x4f60\xd800", false, "%E4%BD%A0%EF%BF%BD"}, | 169 {"\xe4\xbd\xa0\xe5\xa5", L"\x4f60\xd800", false, "%E4%BD%A0%EF%BF%BD"}, |
| 177 // ...same with low surrogates with no high surrogate. | 170 // ...same with low surrogates with no high surrogate. |
| 178 {"\xed\xb0\x80", L"\xdc00", false, "%EF%BF%BD"}, | 171 {"\xed\xb0\x80", L"\xdc00", false, "%EF%BF%BD"}, |
| 179 // Test a UTF-8 encoded surrogate value is marked as invalid. | 172 // Test a UTF-8 encoded surrogate value is marked as invalid. |
| 180 // ED A0 80 = U+D800 | 173 // ED A0 80 = U+D800 |
| 181 {"\xed\xa0\x80", NULL, false, "%EF%BF%BD"}, | 174 {"\xed\xa0\x80", NULL, false, "%EF%BF%BD"}, |
| 182 }; | 175 }; |
| 183 | 176 |
| 184 std::string out_str; | 177 std::string out_str; |
| 185 for (size_t i = 0; i < ARRAYSIZE(utf_cases); i++) { | 178 for (size_t i = 0; i < arraysize(utf_cases); i++) { |
| 186 if (utf_cases[i].input8) { | 179 if (utf_cases[i].input8) { |
| 187 out_str.clear(); | 180 out_str.clear(); |
| 188 StdStringCanonOutput output(&out_str); | 181 StdStringCanonOutput output(&out_str); |
| 189 | 182 |
| 190 int input_len = static_cast<int>(strlen(utf_cases[i].input8)); | 183 int input_len = static_cast<int>(strlen(utf_cases[i].input8)); |
| 191 bool success = true; | 184 bool success = true; |
| 192 for (int ch = 0; ch < input_len; ch++) { | 185 for (int ch = 0; ch < input_len; ch++) { |
| 193 success &= AppendUTF8EscapedChar(utf_cases[i].input8, &ch, input_len, | 186 success &= AppendUTF8EscapedChar(utf_cases[i].input8, &ch, input_len, |
| 194 &output); | 187 &output); |
| 195 } | 188 } |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 {"http://:foo@host.com/", ":foo@", Component(0, 0), Component(1, 3), true}, | 885 {"http://:foo@host.com/", ":foo@", Component(0, 0), Component(1, 3), true}, |
| 893 {"http://^ :$\t@host.com/", "%5E%20:$%09@", Component(0, 6), Component(7, 4)
, true}, | 886 {"http://^ :$\t@host.com/", "%5E%20:$%09@", Component(0, 6), Component(7, 4)
, true}, |
| 894 {"http://user:pass@/", "user:pass@", Component(0, 4), Component(5, 4), true}
, | 887 {"http://user:pass@/", "user:pass@", Component(0, 4), Component(5, 4), true}
, |
| 895 {"http://%2540:bar@domain.com/", "%2540:bar@", Component(0, 5), Component(6,
3), true }, | 888 {"http://%2540:bar@domain.com/", "%2540:bar@", Component(0, 5), Component(6,
3), true }, |
| 896 | 889 |
| 897 // IE7 compatability: old versions allowed backslashes in usernames, but | 890 // IE7 compatability: old versions allowed backslashes in usernames, but |
| 898 // IE7 does not. We disallow it as well. | 891 // IE7 does not. We disallow it as well. |
| 899 {"ftp://me\\mydomain:pass@foo.com/", "", Component(0, -1), Component(0, -1),
true}, | 892 {"ftp://me\\mydomain:pass@foo.com/", "", Component(0, -1), Component(0, -1),
true}, |
| 900 }; | 893 }; |
| 901 | 894 |
| 902 for (size_t i = 0; i < ARRAYSIZE(user_info_cases); i++) { | 895 for (size_t i = 0; i < arraysize(user_info_cases); i++) { |
| 903 int url_len = static_cast<int>(strlen(user_info_cases[i].input)); | 896 int url_len = static_cast<int>(strlen(user_info_cases[i].input)); |
| 904 Parsed parsed; | 897 Parsed parsed; |
| 905 ParseStandardURL(user_info_cases[i].input, url_len, &parsed); | 898 ParseStandardURL(user_info_cases[i].input, url_len, &parsed); |
| 906 Component out_user, out_pass; | 899 Component out_user, out_pass; |
| 907 std::string out_str; | 900 std::string out_str; |
| 908 StdStringCanonOutput output1(&out_str); | 901 StdStringCanonOutput output1(&out_str); |
| 909 | 902 |
| 910 bool success = CanonicalizeUserInfo(user_info_cases[i].input, | 903 bool success = CanonicalizeUserInfo(user_info_cases[i].input, |
| 911 parsed.username, | 904 parsed.username, |
| 912 user_info_cases[i].input, | 905 user_info_cases[i].input, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 // Invalid input should be copied w/ failure. | 954 // Invalid input should be copied w/ failure. |
| 962 {"as df", 80, ":as%20df", Component(1, 7), false}, | 955 {"as df", 80, ":as%20df", Component(1, 7), false}, |
| 963 {"-2", 80, ":-2", Component(1, 2), false}, | 956 {"-2", 80, ":-2", Component(1, 2), false}, |
| 964 // Default port should be omitted. | 957 // Default port should be omitted. |
| 965 {"80", 80, "", Component(0, -1), true}, | 958 {"80", 80, "", Component(0, -1), true}, |
| 966 {"8080", 80, ":8080", Component(1, 4), true}, | 959 {"8080", 80, ":8080", Component(1, 4), true}, |
| 967 // PORT_UNSPECIFIED should mean always keep the port. | 960 // PORT_UNSPECIFIED should mean always keep the port. |
| 968 {"80", PORT_UNSPECIFIED, ":80", Component(1, 2), true}, | 961 {"80", PORT_UNSPECIFIED, ":80", Component(1, 2), true}, |
| 969 }; | 962 }; |
| 970 | 963 |
| 971 for (size_t i = 0; i < ARRAYSIZE(port_cases); i++) { | 964 for (size_t i = 0; i < arraysize(port_cases); i++) { |
| 972 int url_len = static_cast<int>(strlen(port_cases[i].input)); | 965 int url_len = static_cast<int>(strlen(port_cases[i].input)); |
| 973 Component in_comp(0, url_len); | 966 Component in_comp(0, url_len); |
| 974 Component out_comp; | 967 Component out_comp; |
| 975 std::string out_str; | 968 std::string out_str; |
| 976 StdStringCanonOutput output1(&out_str); | 969 StdStringCanonOutput output1(&out_str); |
| 977 bool success = CanonicalizePort(port_cases[i].input, | 970 bool success = CanonicalizePort(port_cases[i].input, |
| 978 in_comp, | 971 in_comp, |
| 979 port_cases[i].default_port, | 972 port_cases[i].default_port, |
| 980 &output1, | 973 &output1, |
| 981 &out_comp); | 974 &out_comp); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 {"q=\xe4\xbd\xa0\xe5\xa5\xbd", L"q=\x4f60\x597d", "?q=%E4%BD%A0%E5%A5%BD"}, | 1138 {"q=\xe4\xbd\xa0\xe5\xa5\xbd", L"q=\x4f60\x597d", "?q=%E4%BD%A0%E5%A5%BD"}, |
| 1146 // Invalid UTF-8/16 input should be replaced with invalid characters. | 1139 // Invalid UTF-8/16 input should be replaced with invalid characters. |
| 1147 {"q=\xed\xed", L"q=\xd800\xd800", "?q=%EF%BF%BD%EF%BF%BD"}, | 1140 {"q=\xed\xed", L"q=\xd800\xd800", "?q=%EF%BF%BD%EF%BF%BD"}, |
| 1148 // Don't allow < or > because sometimes they are used for XSS if the | 1141 // Don't allow < or > because sometimes they are used for XSS if the |
| 1149 // URL is echoed in content. Firefox does this, IE doesn't. | 1142 // URL is echoed in content. Firefox does this, IE doesn't. |
| 1150 {"q=<asdf>", L"q=<asdf>", "?q=%3Casdf%3E"}, | 1143 {"q=<asdf>", L"q=<asdf>", "?q=%3Casdf%3E"}, |
| 1151 // Escape double quotemarks in the query. | 1144 // Escape double quotemarks in the query. |
| 1152 {"q=\"asdf\"", L"q=\"asdf\"", "?q=%22asdf%22"}, | 1145 {"q=\"asdf\"", L"q=\"asdf\"", "?q=%22asdf%22"}, |
| 1153 }; | 1146 }; |
| 1154 | 1147 |
| 1155 for (size_t i = 0; i < ARRAYSIZE(query_cases); i++) { | 1148 for (size_t i = 0; i < arraysize(query_cases); i++) { |
| 1156 Component out_comp; | 1149 Component out_comp; |
| 1157 | 1150 |
| 1158 if (query_cases[i].input8) { | 1151 if (query_cases[i].input8) { |
| 1159 int len = static_cast<int>(strlen(query_cases[i].input8)); | 1152 int len = static_cast<int>(strlen(query_cases[i].input8)); |
| 1160 Component in_comp(0, len); | 1153 Component in_comp(0, len); |
| 1161 std::string out_str; | 1154 std::string out_str; |
| 1162 | 1155 |
| 1163 StdStringCanonOutput output(&out_str); | 1156 StdStringCanonOutput output(&out_str); |
| 1164 CanonicalizeQuery(query_cases[i].input8, in_comp, NULL, &output, | 1157 CanonicalizeQuery(query_cases[i].input8, in_comp, NULL, &output, |
| 1165 &out_comp); | 1158 &out_comp); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 {"ws://foo:80/", "ws://foo/", true}, | 1295 {"ws://foo:80/", "ws://foo/", true}, |
| 1303 {"ws://foo:81/", "ws://foo:81/", true}, | 1296 {"ws://foo:81/", "ws://foo:81/", true}, |
| 1304 {"ws://foo:443/", "ws://foo:443/", true}, | 1297 {"ws://foo:443/", "ws://foo:443/", true}, |
| 1305 {"ws://foo:815/", "ws://foo:815/", true}, | 1298 {"ws://foo:815/", "ws://foo:815/", true}, |
| 1306 {"wss://foo:80/", "wss://foo:80/", true}, | 1299 {"wss://foo:80/", "wss://foo:80/", true}, |
| 1307 {"wss://foo:81/", "wss://foo:81/", true}, | 1300 {"wss://foo:81/", "wss://foo:81/", true}, |
| 1308 {"wss://foo:443/", "wss://foo/", true}, | 1301 {"wss://foo:443/", "wss://foo/", true}, |
| 1309 {"wss://foo:815/", "wss://foo:815/", true}, | 1302 {"wss://foo:815/", "wss://foo:815/", true}, |
| 1310 }; | 1303 }; |
| 1311 | 1304 |
| 1312 for (size_t i = 0; i < ARRAYSIZE(cases); i++) { | 1305 for (size_t i = 0; i < arraysize(cases); i++) { |
| 1313 int url_len = static_cast<int>(strlen(cases[i].input)); | 1306 int url_len = static_cast<int>(strlen(cases[i].input)); |
| 1314 Parsed parsed; | 1307 Parsed parsed; |
| 1315 ParseStandardURL(cases[i].input, url_len, &parsed); | 1308 ParseStandardURL(cases[i].input, url_len, &parsed); |
| 1316 | 1309 |
| 1317 Parsed out_parsed; | 1310 Parsed out_parsed; |
| 1318 std::string out_str; | 1311 std::string out_str; |
| 1319 StdStringCanonOutput output(&out_str); | 1312 StdStringCanonOutput output(&out_str); |
| 1320 bool success = CanonicalizeStandardURL( | 1313 bool success = CanonicalizeStandardURL( |
| 1321 cases[i].input, url_len, parsed, NULL, &output, &out_parsed); | 1314 cases[i].input, url_len, parsed, NULL, &output, &out_parsed); |
| 1322 output.Complete(); | 1315 output.Complete(); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1641 {"//", "file:///", true, Component(), Component(7, 1)}, | 1634 {"//", "file:///", true, Component(), Component(7, 1)}, |
| 1642 {"///", "file:///", true, Component(), Component(7, 1)}, | 1635 {"///", "file:///", true, Component(), Component(7, 1)}, |
| 1643 {"///test", "file:///test", true, Component(), Component(7, 5)}, | 1636 {"///test", "file:///test", true, Component(), Component(7, 5)}, |
| 1644 {"file://test", "file://test/", true, Component(7, 4), Component(11, 1)}, | 1637 {"file://test", "file://test/", true, Component(7, 4), Component(11, 1)}, |
| 1645 {"file://localhost", "file://localhost/", true, Component(7, 9), Component(
16, 1)}, | 1638 {"file://localhost", "file://localhost/", true, Component(7, 9), Component(
16, 1)}, |
| 1646 {"file://localhost/", "file://localhost/", true, Component(7, 9), Component(
16, 1)}, | 1639 {"file://localhost/", "file://localhost/", true, Component(7, 9), Component(
16, 1)}, |
| 1647 {"file://localhost/test", "file://localhost/test", true, Component(7, 9), Co
mponent(16, 5)}, | 1640 {"file://localhost/test", "file://localhost/test", true, Component(7, 9), Co
mponent(16, 5)}, |
| 1648 #endif // _WIN32 | 1641 #endif // _WIN32 |
| 1649 }; | 1642 }; |
| 1650 | 1643 |
| 1651 for (size_t i = 0; i < ARRAYSIZE(cases); i++) { | 1644 for (size_t i = 0; i < arraysize(cases); i++) { |
| 1652 int url_len = static_cast<int>(strlen(cases[i].input)); | 1645 int url_len = static_cast<int>(strlen(cases[i].input)); |
| 1653 Parsed parsed; | 1646 Parsed parsed; |
| 1654 ParseFileURL(cases[i].input, url_len, &parsed); | 1647 ParseFileURL(cases[i].input, url_len, &parsed); |
| 1655 | 1648 |
| 1656 Parsed out_parsed; | 1649 Parsed out_parsed; |
| 1657 std::string out_str; | 1650 std::string out_str; |
| 1658 StdStringCanonOutput output(&out_str); | 1651 StdStringCanonOutput output(&out_str); |
| 1659 bool success = CanonicalizeFileURL(cases[i].input, url_len, parsed, NULL, | 1652 bool success = CanonicalizeFileURL(cases[i].input, url_len, parsed, NULL, |
| 1660 &output, &out_parsed); | 1653 &output, &out_parsed); |
| 1661 output.Complete(); | 1654 output.Complete(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1684 } cases[] = { | 1677 } cases[] = { |
| 1685 {"Filesystem:htTp://www.Foo.com:80/tempoRary", "filesystem:http://www.foo.co
m/tempoRary/", true}, | 1678 {"Filesystem:htTp://www.Foo.com:80/tempoRary", "filesystem:http://www.foo.co
m/tempoRary/", true}, |
| 1686 {"filesystem:httpS://www.foo.com/temporary/", "filesystem:https://www.foo.co
m/temporary/", true}, | 1679 {"filesystem:httpS://www.foo.com/temporary/", "filesystem:https://www.foo.co
m/temporary/", true}, |
| 1687 {"filesystem:http://www.foo.com//", "filesystem:http://www.foo.com//", false
}, | 1680 {"filesystem:http://www.foo.com//", "filesystem:http://www.foo.com//", false
}, |
| 1688 {"filesystem:http://www.foo.com/persistent/bob?query#ref", "filesystem:http:
//www.foo.com/persistent/bob?query#ref", true}, | 1681 {"filesystem:http://www.foo.com/persistent/bob?query#ref", "filesystem:http:
//www.foo.com/persistent/bob?query#ref", true}, |
| 1689 {"filesystem:fIle://\\temporary/", "filesystem:file:///temporary/", true}, | 1682 {"filesystem:fIle://\\temporary/", "filesystem:file:///temporary/", true}, |
| 1690 {"filesystem:fiLe:///temporary", "filesystem:file:///temporary/", true}, | 1683 {"filesystem:fiLe:///temporary", "filesystem:file:///temporary/", true}, |
| 1691 {"filesystem:File:///temporary/Bob?qUery#reF", "filesystem:file:///temporary
/Bob?qUery#reF", true}, | 1684 {"filesystem:File:///temporary/Bob?qUery#reF", "filesystem:file:///temporary
/Bob?qUery#reF", true}, |
| 1692 }; | 1685 }; |
| 1693 | 1686 |
| 1694 for (size_t i = 0; i < ARRAYSIZE(cases); i++) { | 1687 for (size_t i = 0; i < arraysize(cases); i++) { |
| 1695 int url_len = static_cast<int>(strlen(cases[i].input)); | 1688 int url_len = static_cast<int>(strlen(cases[i].input)); |
| 1696 Parsed parsed; | 1689 Parsed parsed; |
| 1697 ParseFileSystemURL(cases[i].input, url_len, &parsed); | 1690 ParseFileSystemURL(cases[i].input, url_len, &parsed); |
| 1698 | 1691 |
| 1699 Parsed out_parsed; | 1692 Parsed out_parsed; |
| 1700 std::string out_str; | 1693 std::string out_str; |
| 1701 StdStringCanonOutput output(&out_str); | 1694 StdStringCanonOutput output(&out_str); |
| 1702 bool success = CanonicalizeFileSystemURL(cases[i].input, url_len, parsed, | 1695 bool success = CanonicalizeFileSystemURL(cases[i].input, url_len, parsed, |
| 1703 NULL, &output, &out_parsed); | 1696 NULL, &output, &out_parsed); |
| 1704 output.Complete(); | 1697 output.Complete(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1719 // Path URLs should get canonicalized schemes but nothing else. | 1712 // Path URLs should get canonicalized schemes but nothing else. |
| 1720 struct PathCase { | 1713 struct PathCase { |
| 1721 const char* input; | 1714 const char* input; |
| 1722 const char* expected; | 1715 const char* expected; |
| 1723 } path_cases[] = { | 1716 } path_cases[] = { |
| 1724 {"javascript:", "javascript:"}, | 1717 {"javascript:", "javascript:"}, |
| 1725 {"JavaScript:Foo", "javascript:Foo"}, | 1718 {"JavaScript:Foo", "javascript:Foo"}, |
| 1726 {":\":This /is interesting;?#", ":\":This /is interesting;?#"}, | 1719 {":\":This /is interesting;?#", ":\":This /is interesting;?#"}, |
| 1727 }; | 1720 }; |
| 1728 | 1721 |
| 1729 for (size_t i = 0; i < ARRAYSIZE(path_cases); i++) { | 1722 for (size_t i = 0; i < arraysize(path_cases); i++) { |
| 1730 int url_len = static_cast<int>(strlen(path_cases[i].input)); | 1723 int url_len = static_cast<int>(strlen(path_cases[i].input)); |
| 1731 Parsed parsed; | 1724 Parsed parsed; |
| 1732 ParsePathURL(path_cases[i].input, url_len, true, &parsed); | 1725 ParsePathURL(path_cases[i].input, url_len, true, &parsed); |
| 1733 | 1726 |
| 1734 Parsed out_parsed; | 1727 Parsed out_parsed; |
| 1735 std::string out_str; | 1728 std::string out_str; |
| 1736 StdStringCanonOutput output(&out_str); | 1729 StdStringCanonOutput output(&out_str); |
| 1737 bool success = CanonicalizePathURL(path_cases[i].input, url_len, parsed, | 1730 bool success = CanonicalizePathURL(path_cases[i].input, url_len, parsed, |
| 1738 &output, &out_parsed); | 1731 &output, &out_parsed); |
| 1739 output.Complete(); | 1732 output.Complete(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1773 {"mailto:addr1\0addr2?foo", "mailto:addr1%00addr2?foo", true, Component(7, 1
3), Component(21, 3)}, | 1766 {"mailto:addr1\0addr2?foo", "mailto:addr1%00addr2?foo", true, Component(7, 1
3), Component(21, 3)}, |
| 1774 // Invalid -- UTF-8 encoded surrogate value. | 1767 // Invalid -- UTF-8 encoded surrogate value. |
| 1775 {"mailto:\xed\xa0\x80", "mailto:%EF%BF%BD", false, Component(7, 9), Componen
t()}, | 1768 {"mailto:\xed\xa0\x80", "mailto:%EF%BF%BD", false, Component(7, 9), Componen
t()}, |
| 1776 {"mailto:addr1?", "mailto:addr1?", true, Component(7, 5), Component(13, 0)}, | 1769 {"mailto:addr1?", "mailto:addr1?", true, Component(7, 5), Component(13, 0)}, |
| 1777 }; | 1770 }; |
| 1778 | 1771 |
| 1779 // Define outside of loop to catch bugs where components aren't reset | 1772 // Define outside of loop to catch bugs where components aren't reset |
| 1780 Parsed parsed; | 1773 Parsed parsed; |
| 1781 Parsed out_parsed; | 1774 Parsed out_parsed; |
| 1782 | 1775 |
| 1783 for (size_t i = 0; i < ARRAYSIZE(cases); i++) { | 1776 for (size_t i = 0; i < arraysize(cases); i++) { |
| 1784 int url_len = static_cast<int>(strlen(cases[i].input)); | 1777 int url_len = static_cast<int>(strlen(cases[i].input)); |
| 1785 if (i == 8) { | 1778 if (i == 8) { |
| 1786 // The 9th test case purposely has a '\0' in it -- don't count it | 1779 // The 9th test case purposely has a '\0' in it -- don't count it |
| 1787 // as the string terminator. | 1780 // as the string terminator. |
| 1788 url_len = 22; | 1781 url_len = 22; |
| 1789 } | 1782 } |
| 1790 ParseMailtoURL(cases[i].input, url_len, &parsed); | 1783 ParseMailtoURL(cases[i].input, url_len, &parsed); |
| 1791 | 1784 |
| 1792 std::string out_str; | 1785 std::string out_str; |
| 1793 StdStringCanonOutput output(&out_str); | 1786 StdStringCanonOutput output(&out_str); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2036 {"filesystem:http://host/t/path", true, false, "http://host/t/path2", true,
false, false, NULL}, | 2029 {"filesystem:http://host/t/path", true, false, "http://host/t/path2", true,
false, false, NULL}, |
| 2037 {"http://host/t/path", true, false, "filesystem:http://host/t/path2", true,
false, false, NULL}, | 2030 {"http://host/t/path", true, false, "filesystem:http://host/t/path2", true,
false, false, NULL}, |
| 2038 {"filesystem:http://host/t/path", true, false, "./path2", true, true, true,
"filesystem:http://host/t/path2"}, | 2031 {"filesystem:http://host/t/path", true, false, "./path2", true, true, true,
"filesystem:http://host/t/path2"}, |
| 2039 {"filesystem:http://host/t/path/", true, false, "path2", true, true, true, "
filesystem:http://host/t/path/path2"}, | 2032 {"filesystem:http://host/t/path/", true, false, "path2", true, true, true, "
filesystem:http://host/t/path/path2"}, |
| 2040 {"filesystem:http://host/t/path", true, false, "filesystem:http:path2", true
, false, false, NULL}, | 2033 {"filesystem:http://host/t/path", true, false, "filesystem:http:path2", true
, false, false, NULL}, |
| 2041 // Absolute URLs are still not relative to a non-standard base URL. | 2034 // Absolute URLs are still not relative to a non-standard base URL. |
| 2042 {"about:blank", false, false, "http://X/A", true, false, true, ""}, | 2035 {"about:blank", false, false, "http://X/A", true, false, true, ""}, |
| 2043 {"about:blank", false, false, "content://content.Provider/", true, false, tr
ue, ""}, | 2036 {"about:blank", false, false, "content://content.Provider/", true, false, tr
ue, ""}, |
| 2044 }; | 2037 }; |
| 2045 | 2038 |
| 2046 for (size_t i = 0; i < ARRAYSIZE(rel_cases); i++) { | 2039 for (size_t i = 0; i < arraysize(rel_cases); i++) { |
| 2047 const RelativeCase& cur_case = rel_cases[i]; | 2040 const RelativeCase& cur_case = rel_cases[i]; |
| 2048 | 2041 |
| 2049 Parsed parsed; | 2042 Parsed parsed; |
| 2050 int base_len = static_cast<int>(strlen(cur_case.base)); | 2043 int base_len = static_cast<int>(strlen(cur_case.base)); |
| 2051 if (cur_case.is_base_file) | 2044 if (cur_case.is_base_file) |
| 2052 ParseFileURL(cur_case.base, base_len, &parsed); | 2045 ParseFileURL(cur_case.base, base_len, &parsed); |
| 2053 else if (cur_case.is_base_hier) | 2046 else if (cur_case.is_base_hier) |
| 2054 ParseStandardURL(cur_case.base, base_len, &parsed); | 2047 ParseStandardURL(cur_case.base, base_len, &parsed); |
| 2055 else | 2048 else |
| 2056 ParsePathURL(cur_case.base, base_len, false, &parsed); | 2049 ParsePathURL(cur_case.base, base_len, false, &parsed); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 repl_output.Complete(); | 2122 repl_output.Complete(); |
| 2130 | 2123 |
| 2131 // Generate the expected string and check. | 2124 // Generate the expected string and check. |
| 2132 std::string expected("file:///foo?"); | 2125 std::string expected("file:///foo?"); |
| 2133 for (size_t i = 0; i < new_query.length(); i++) | 2126 for (size_t i = 0; i < new_query.length(); i++) |
| 2134 expected.push_back('a'); | 2127 expected.push_back('a'); |
| 2135 EXPECT_TRUE(expected == repl_str); | 2128 EXPECT_TRUE(expected == repl_str); |
| 2136 } | 2129 } |
| 2137 | 2130 |
| 2138 } // namespace url | 2131 } // namespace url |
| OLD | NEW |