1/*
2 * Copyright (C) 2016 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "WTFStringUtilities.h"
28#include <wtf/MainThread.h>
29#include <wtf/URLParser.h>
30#include <wtf/text/StringBuilder.h>
31
32namespace TestWebKitAPI {
33
34class WTF_URLParser : public testing::Test {
35public:
36 void SetUp() final
37 {
38 WTF::initializeMainThread();
39 }
40};
41
42struct ExpectedParts {
43 String protocol;
44 String user;
45 String password;
46 String host;
47 unsigned short port;
48 String path;
49 String query;
50 String fragment;
51 String string;
52
53 bool isInvalid() const
54 {
55 return protocol.isEmpty()
56 && user.isEmpty()
57 && password.isEmpty()
58 && host.isEmpty()
59 && !port
60 && path.isEmpty()
61 && query.isEmpty()
62 && fragment.isEmpty();
63 }
64};
65
66template<typename T, typename U>
67bool eq(T&& s1, U&& s2)
68{
69 EXPECT_STREQ(s1.utf8().data(), s2.utf8().data());
70 return s1.utf8() == s2.utf8();
71}
72
73static String insertTabAtLocation(const String& string, size_t location)
74{
75 ASSERT(location <= string.length());
76 return makeString(string.substring(0, location), "\t", string.substring(location));
77}
78
79static ExpectedParts invalidParts(const String& urlStringWithTab)
80{
81 return {"", "", "", "", 0, "" , "", "", urlStringWithTab};
82}
83
84enum class TestTabs { No, Yes };
85
86// Inserting tabs between surrogate pairs changes the encoded value instead of being skipped by the URLParser.
87const TestTabs testTabsValueForSurrogatePairs = TestTabs::No;
88
89static void checkURL(const String& urlString, const ExpectedParts& parts, TestTabs testTabs = TestTabs::Yes)
90{
91 auto url = URL(URL(), urlString);
92
93 EXPECT_TRUE(eq(parts.protocol, url.protocol()));
94 EXPECT_TRUE(eq(parts.user, url.user()));
95 EXPECT_TRUE(eq(parts.password, url.pass()));
96 EXPECT_TRUE(eq(parts.host, url.host()));
97 EXPECT_EQ(parts.port, url.port().valueOr(0));
98 EXPECT_TRUE(eq(parts.path, url.path()));
99 EXPECT_TRUE(eq(parts.query, url.query()));
100 EXPECT_TRUE(eq(parts.fragment, url.fragmentIdentifier()));
101 EXPECT_TRUE(eq(parts.string, url.string()));
102
103 EXPECT_TRUE(WTF::URLParser::internalValuesConsistent(url));
104
105 if (testTabs == TestTabs::No)
106 return;
107
108 for (size_t i = 0; i < urlString.length(); ++i) {
109 String urlStringWithTab = insertTabAtLocation(urlString, i);
110 checkURL(urlStringWithTab,
111 parts.isInvalid() ? invalidParts(urlStringWithTab) : parts,
112 TestTabs::No);
113 }
114}
115
116static void checkRelativeURL(const String& urlString, const String& baseURLString, const ExpectedParts& parts, TestTabs testTabs = TestTabs::Yes)
117{
118 auto url = URL(URL(URL(), baseURLString), urlString);
119
120 EXPECT_TRUE(eq(parts.protocol, url.protocol()));
121 EXPECT_TRUE(eq(parts.user, url.user()));
122 EXPECT_TRUE(eq(parts.password, url.pass()));
123 EXPECT_TRUE(eq(parts.host, url.host()));
124 EXPECT_EQ(parts.port, url.port().valueOr(0));
125 EXPECT_TRUE(eq(parts.path, url.path()));
126 EXPECT_TRUE(eq(parts.query, url.query()));
127 EXPECT_TRUE(eq(parts.fragment, url.fragmentIdentifier()));
128 EXPECT_TRUE(eq(parts.string, url.string()));
129
130 EXPECT_TRUE(WTF::URLParser::internalValuesConsistent(url));
131
132 if (testTabs == TestTabs::No)
133 return;
134
135 for (size_t i = 0; i < urlString.length(); ++i) {
136 String urlStringWithTab = insertTabAtLocation(urlString, i);
137 checkRelativeURL(urlStringWithTab,
138 baseURLString,
139 parts.isInvalid() ? invalidParts(urlStringWithTab) : parts,
140 TestTabs::No);
141 }
142}
143
144static void checkURLDifferences(const String& urlString, const ExpectedParts& partsNew, const ExpectedParts& partsOld, TestTabs testTabs = TestTabs::Yes)
145{
146 UNUSED_PARAM(partsOld); // FIXME: Remove all the old expected parts.
147 auto url = URL(URL(), urlString);
148
149 EXPECT_TRUE(eq(partsNew.protocol, url.protocol()));
150 EXPECT_TRUE(eq(partsNew.user, url.user()));
151 EXPECT_TRUE(eq(partsNew.password, url.pass()));
152 EXPECT_TRUE(eq(partsNew.host, url.host()));
153 EXPECT_EQ(partsNew.port, url.port().valueOr(0));
154 EXPECT_TRUE(eq(partsNew.path, url.path()));
155 EXPECT_TRUE(eq(partsNew.query, url.query()));
156 EXPECT_TRUE(eq(partsNew.fragment, url.fragmentIdentifier()));
157 EXPECT_TRUE(eq(partsNew.string, url.string()));
158
159 EXPECT_TRUE(WTF::URLParser::internalValuesConsistent(url));
160
161 if (testTabs == TestTabs::No)
162 return;
163
164 for (size_t i = 0; i < urlString.length(); ++i) {
165 String urlStringWithTab = insertTabAtLocation(urlString, i);
166 checkURLDifferences(urlStringWithTab,
167 partsNew.isInvalid() ? invalidParts(urlStringWithTab) : partsNew,
168 partsOld.isInvalid() ? invalidParts(urlStringWithTab) : partsOld,
169 TestTabs::No);
170 }
171}
172
173static void checkRelativeURLDifferences(const String& urlString, const String& baseURLString, const ExpectedParts& partsNew, const ExpectedParts& partsOld, TestTabs testTabs = TestTabs::Yes)
174{
175 UNUSED_PARAM(partsOld); // FIXME: Remove all the old expected parts.
176 auto url = URL(URL(URL(), baseURLString), urlString);
177
178 EXPECT_TRUE(eq(partsNew.protocol, url.protocol()));
179 EXPECT_TRUE(eq(partsNew.user, url.user()));
180 EXPECT_TRUE(eq(partsNew.password, url.pass()));
181 EXPECT_TRUE(eq(partsNew.host, url.host()));
182 EXPECT_EQ(partsNew.port, url.port().valueOr(0));
183 EXPECT_TRUE(eq(partsNew.path, url.path()));
184 EXPECT_TRUE(eq(partsNew.query, url.query()));
185 EXPECT_TRUE(eq(partsNew.fragment, url.fragmentIdentifier()));
186 EXPECT_TRUE(eq(partsNew.string, url.string()));
187
188 EXPECT_TRUE(WTF::URLParser::internalValuesConsistent(url));
189
190 if (testTabs == TestTabs::No)
191 return;
192
193 for (size_t i = 0; i < urlString.length(); ++i) {
194 String urlStringWithTab = insertTabAtLocation(urlString, i);
195 checkRelativeURLDifferences(urlStringWithTab, baseURLString,
196 partsNew.isInvalid() ? invalidParts(urlStringWithTab) : partsNew,
197 partsOld.isInvalid() ? invalidParts(urlStringWithTab) : partsOld,
198 TestTabs::No);
199 }
200}
201
202static void shouldFail(const String& urlString)
203{
204 checkURL(urlString, {"", "", "", "", 0, "", "", "", urlString});
205}
206
207static void shouldFail(const String& urlString, const String& baseString)
208{
209 checkRelativeURL(urlString, baseString, {"", "", "", "", 0, "", "", "", urlString});
210}
211
212TEST_F(WTF_URLParser, Basic)
213{
214 checkURL("http://user:[email protected]:123/path?query#fragment", {"http", "user", "pass", "webkit.org", 123, "/path", "query", "fragment", "http://user:[email protected]:123/path?query#fragment"});
215 checkURL("http://user:[email protected]:123/path?query", {"http", "user", "pass", "webkit.org", 123, "/path", "query", "", "http://user:[email protected]:123/path?query"});
216 checkURL("http://user:[email protected]:123/path", {"http", "user", "pass", "webkit.org", 123, "/path", "", "", "http://user:[email protected]:123/path"});
217 checkURL("http://user:[email protected]:123/", {"http", "user", "pass", "webkit.org", 123, "/", "", "", "http://user:[email protected]:123/"});
218 checkURL("http://user:[email protected]:123", {"http", "user", "pass", "webkit.org", 123, "/", "", "", "http://user:[email protected]:123/"});
219 checkURL("http://user:[email protected]", {"http", "user", "pass", "webkit.org", 0, "/", "", "", "http://user:[email protected]/"});
220 checkURL("http://user:\t\t\[email protected]", {"http", "user", "pass", "webkit.org", 0, "/", "", "", "http://user:[email protected]/"});
221 checkURL("http://us\ter:[email protected]", {"http", "user", "pass", "webkit.org", 0, "/", "", "", "http://user:[email protected]/"});
222 checkURL("http://user:pa\[email protected]", {"http", "user", "pass", "webkit.org", 0, "/", "", "", "http://user:[email protected]/"});
223 checkURL("http://user:pass\[email protected]", {"http", "user", "pass", "webkit.org", 0, "/", "", "", "http://user:[email protected]/"});
224 checkURL("http://\tuser:[email protected]", {"http", "user", "pass", "webkit.org", 0, "/", "", "", "http://user:[email protected]/"});
225 checkURL("http://user\t:[email protected]", {"http", "user", "pass", "webkit.org", 0, "/", "", "", "http://user:[email protected]/"});
226 checkURL("http://webkit.org", {"http", "", "", "webkit.org", 0, "/", "", "", "http://webkit.org/"});
227 checkURL("http://127.0.0.1", {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"});
228 checkURL("http://webkit.org/", {"http", "", "", "webkit.org", 0, "/", "", "", "http://webkit.org/"});
229 checkURL("http://webkit.org/path1/path2/index.html", {"http", "", "", "webkit.org", 0, "/path1/path2/index.html", "", "", "http://webkit.org/path1/path2/index.html"});
230 checkURL("about:blank", {"about", "", "", "", 0, "blank", "", "", "about:blank"});
231 checkURL("about:blank?query", {"about", "", "", "", 0, "blank", "query", "", "about:blank?query"});
232 checkURL("about:blank#fragment", {"about", "", "", "", 0, "blank", "", "fragment", "about:blank#fragment"});
233 checkURL("http://[0::0]/", {"http", "", "", "[::]", 0, "/", "", "", "http://[::]/"});
234 checkURL("http://[0::]/", {"http", "", "", "[::]", 0, "/", "", "", "http://[::]/"});
235 checkURL("http://[::]/", {"http", "", "", "[::]", 0, "/", "", "", "http://[::]/"});
236 checkURL("http://[::0]/", {"http", "", "", "[::]", 0, "/", "", "", "http://[::]/"});
237 checkURL("http://[::0:0]/", {"http", "", "", "[::]", 0, "/", "", "", "http://[::]/"});
238 checkURL("http://[f::0:0]/", {"http", "", "", "[f::]", 0, "/", "", "", "http://[f::]/"});
239 checkURL("http://[f:0::f]/", {"http", "", "", "[f::f]", 0, "/", "", "", "http://[f::f]/"});
240 checkURL("http://[::0:ff]/", {"http", "", "", "[::ff]", 0, "/", "", "", "http://[::ff]/"});
241 checkURL("http://[::00:0:0:0]/", {"http", "", "", "[::]", 0, "/", "", "", "http://[::]/"});
242 checkURL("http://[::0:00:0:0]/", {"http", "", "", "[::]", 0, "/", "", "", "http://[::]/"});
243 checkURL("http://[::0:0.0.0.0]/", {"http", "", "", "[::]", 0, "/", "", "", "http://[::]/"});
244 checkURL("http://[0:f::f:f:0:0]", {"http", "", "", "[0:f::f:f:0:0]", 0, "/", "", "", "http://[0:f::f:f:0:0]/"});
245 checkURL("http://[0:f:0:0:f::]", {"http", "", "", "[0:f:0:0:f::]", 0, "/", "", "", "http://[0:f:0:0:f::]/"});
246 checkURL("http://[::f:0:0:f:0:0]", {"http", "", "", "[::f:0:0:f:0:0]", 0, "/", "", "", "http://[::f:0:0:f:0:0]/"});
247 checkURL("http://[0:f:0:0:f::]:", {"http", "", "", "[0:f:0:0:f::]", 0, "/", "", "", "http://[0:f:0:0:f::]/"});
248 checkURL("http://[0:f:0:0:f::]:\t", {"http", "", "", "[0:f:0:0:f::]", 0, "/", "", "", "http://[0:f:0:0:f::]/"});
249 checkURL("http://[0:f:0:0:f::]\t:", {"http", "", "", "[0:f:0:0:f::]", 0, "/", "", "", "http://[0:f:0:0:f::]/"});
250 checkURL("http://\t[::f:0:0:f:0:0]", {"http", "", "", "[::f:0:0:f:0:0]", 0, "/", "", "", "http://[::f:0:0:f:0:0]/"});
251 checkURL("http://[\t::f:0:0:f:0:0]", {"http", "", "", "[::f:0:0:f:0:0]", 0, "/", "", "", "http://[::f:0:0:f:0:0]/"});
252 checkURL("http://[:\t:f:0:0:f:0:0]", {"http", "", "", "[::f:0:0:f:0:0]", 0, "/", "", "", "http://[::f:0:0:f:0:0]/"});
253 checkURL("http://[::\tf:0:0:f:0:0]", {"http", "", "", "[::f:0:0:f:0:0]", 0, "/", "", "", "http://[::f:0:0:f:0:0]/"});
254 checkURL("http://[::f\t:0:0:f:0:0]", {"http", "", "", "[::f:0:0:f:0:0]", 0, "/", "", "", "http://[::f:0:0:f:0:0]/"});
255 checkURL("http://[::f:\t0:0:f:0:0]", {"http", "", "", "[::f:0:0:f:0:0]", 0, "/", "", "", "http://[::f:0:0:f:0:0]/"});
256 checkURL("http://example.com/path1/path2/.", {"http", "", "", "example.com", 0, "/path1/path2/", "", "", "http://example.com/path1/path2/"});
257 checkURL("http://example.com/path1/path2/..", {"http", "", "", "example.com", 0, "/path1/", "", "", "http://example.com/path1/"});
258 checkURL("http://example.com/path1/path2/./path3", {"http", "", "", "example.com", 0, "/path1/path2/path3", "", "", "http://example.com/path1/path2/path3"});
259 checkURL("http://example.com/path1/path2/.\\path3", {"http", "", "", "example.com", 0, "/path1/path2/path3", "", "", "http://example.com/path1/path2/path3"});
260 checkURL("http://example.com/path1/path2/../path3", {"http", "", "", "example.com", 0, "/path1/path3", "", "", "http://example.com/path1/path3"});
261 checkURL("http://example.com/path1/path2/..\\path3", {"http", "", "", "example.com", 0, "/path1/path3", "", "", "http://example.com/path1/path3"});
262 checkURL("http://example.com/.", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
263 checkURL("http://example.com/..", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
264 checkURL("http://example.com/./path1", {"http", "", "", "example.com", 0, "/path1", "", "", "http://example.com/path1"});
265 checkURL("http://example.com/../path1", {"http", "", "", "example.com", 0, "/path1", "", "", "http://example.com/path1"});
266 checkURL("http://example.com/../path1/../../path2/path3/../path4", {"http", "", "", "example.com", 0, "/path2/path4", "", "", "http://example.com/path2/path4"});
267 checkURL("http://example.com/path1/.%2", {"http", "", "", "example.com", 0, "/path1/.%2", "", "", "http://example.com/path1/.%2"});
268 checkURL("http://example.com/path1/%2", {"http", "", "", "example.com", 0, "/path1/%2", "", "", "http://example.com/path1/%2"});
269 checkURL("http://example.com/path1/%", {"http", "", "", "example.com", 0, "/path1/%", "", "", "http://example.com/path1/%"});
270 checkURL("http://example.com/path1/.%", {"http", "", "", "example.com", 0, "/path1/.%", "", "", "http://example.com/path1/.%"});
271 checkURL("http://example.com//.", {"http", "", "", "example.com", 0, "//", "", "", "http://example.com//"});
272 checkURL("http://example.com//./", {"http", "", "", "example.com", 0, "//", "", "", "http://example.com//"});
273 checkURL("http://example.com//.//", {"http", "", "", "example.com", 0, "///", "", "", "http://example.com///"});
274 checkURL("http://example.com//..", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
275 checkURL("http://example.com//../", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
276 checkURL("http://example.com//..//", {"http", "", "", "example.com", 0, "//", "", "", "http://example.com//"});
277 checkURL("http://example.com//..", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
278 checkURL("http://example.com/.//", {"http", "", "", "example.com", 0, "//", "", "", "http://example.com//"});
279 checkURL("http://example.com/..//", {"http", "", "", "example.com", 0, "//", "", "", "http://example.com//"});
280 checkURL("http://example.com/./", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
281 checkURL("http://example.com/../", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
282 checkURL("http://example.com/path1/.../path3", {"http", "", "", "example.com", 0, "/path1/.../path3", "", "", "http://example.com/path1/.../path3"});
283 checkURL("http://example.com/path1/...", {"http", "", "", "example.com", 0, "/path1/...", "", "", "http://example.com/path1/..."});
284 checkURL("http://example.com/path1/.../", {"http", "", "", "example.com", 0, "/path1/.../", "", "", "http://example.com/path1/.../"});
285 checkURL("http://example.com/.path1/", {"http", "", "", "example.com", 0, "/.path1/", "", "", "http://example.com/.path1/"});
286 checkURL("http://example.com/..path1/", {"http", "", "", "example.com", 0, "/..path1/", "", "", "http://example.com/..path1/"});
287 checkURL("http://example.com/path1/.path2", {"http", "", "", "example.com", 0, "/path1/.path2", "", "", "http://example.com/path1/.path2"});
288 checkURL("http://example.com/path1/..path2", {"http", "", "", "example.com", 0, "/path1/..path2", "", "", "http://example.com/path1/..path2"});
289 checkURL("http://example.com/path1/path2/.?query", {"http", "", "", "example.com", 0, "/path1/path2/", "query", "", "http://example.com/path1/path2/?query"});
290 checkURL("http://example.com/path1/path2/..?query", {"http", "", "", "example.com", 0, "/path1/", "query", "", "http://example.com/path1/?query"});
291 checkURL("http://example.com/path1/path2/.#fragment", {"http", "", "", "example.com", 0, "/path1/path2/", "", "fragment", "http://example.com/path1/path2/#fragment"});
292 checkURL("http://example.com/path1/path2/..#fragment", {"http", "", "", "example.com", 0, "/path1/", "", "fragment", "http://example.com/path1/#fragment"});
293
294 checkURL("file:", {"file", "", "", "", 0, "/", "", "", "file:///"});
295 checkURL("file:/", {"file", "", "", "", 0, "/", "", "", "file:///"});
296 checkURL("file://", {"file", "", "", "", 0, "/", "", "", "file:///"});
297 checkURL("file:///", {"file", "", "", "", 0, "/", "", "", "file:///"});
298 checkURL("file:////", {"file", "", "", "", 0, "//", "", "", "file:////"}); // This matches Firefox and URL::parse which I believe are correct, but not Chrome.
299 checkURL("file:/path", {"file", "", "", "", 0, "/path", "", "", "file:///path"});
300 checkURL("file://host/path", {"file", "", "", "host", 0, "/path", "", "", "file://host/path"});
301 checkURL("file://host", {"file", "", "", "host", 0, "/", "", "", "file://host/"});
302 checkURL("file://host/", {"file", "", "", "host", 0, "/", "", "", "file://host/"});
303 checkURL("file:///path", {"file", "", "", "", 0, "/path", "", "", "file:///path"});
304 checkURL("file:////path", {"file", "", "", "", 0, "//path", "", "", "file:////path"});
305 checkURL("file://localhost/path", {"file", "", "", "", 0, "/path", "", "", "file:///path"});
306 checkURL("file://localhost/", {"file", "", "", "", 0, "/", "", "", "file:///"});
307 checkURL("file://localhost", {"file", "", "", "", 0, "/", "", "", "file:///"});
308 checkURL("file://lOcAlHoSt", {"file", "", "", "", 0, "/", "", "", "file:///"});
309 checkURL("file://lOcAlHoSt/", {"file", "", "", "", 0, "/", "", "", "file:///"});
310 checkURL("file:/pAtH/", {"file", "", "", "", 0, "/pAtH/", "", "", "file:///pAtH/"});
311 checkURL("file:/pAtH", {"file", "", "", "", 0, "/pAtH", "", "", "file:///pAtH"});
312 checkURL("file:?query", {"file", "", "", "", 0, "/", "query", "", "file:///?query"});
313 checkURL("file:#fragment", {"file", "", "", "", 0, "/", "", "fragment", "file:///#fragment"});
314 checkURL("file:?query#fragment", {"file", "", "", "", 0, "/", "query", "fragment", "file:///?query#fragment"});
315 checkURL("file:#fragment?notquery", {"file", "", "", "", 0, "/", "", "fragment?notquery", "file:///#fragment?notquery"});
316 checkURL("file:/?query", {"file", "", "", "", 0, "/", "query", "", "file:///?query"});
317 checkURL("file:/#fragment", {"file", "", "", "", 0, "/", "", "fragment", "file:///#fragment"});
318 checkURL("file://?query", {"file", "", "", "", 0, "/", "query", "", "file:///?query"});
319 checkURL("file://#fragment", {"file", "", "", "", 0, "/", "", "fragment", "file:///#fragment"});
320 checkURL("file:///?query", {"file", "", "", "", 0, "/", "query", "", "file:///?query"});
321 checkURL("file:///#fragment", {"file", "", "", "", 0, "/", "", "fragment", "file:///#fragment"});
322 checkURL("file:////?query", {"file", "", "", "", 0, "//", "query", "", "file:////?query"});
323 checkURL("file:////#fragment", {"file", "", "", "", 0, "//", "", "fragment", "file:////#fragment"});
324 checkURL("file://?Q", {"file", "", "", "", 0, "/", "Q", "", "file:///?Q"});
325 checkURL("file://#F", {"file", "", "", "", 0, "/", "", "F", "file:///#F"});
326 checkURL("file://host?Q", {"file", "", "", "host", 0, "/", "Q", "", "file://host/?Q"});
327 checkURL("file://host#F", {"file", "", "", "host", 0, "/", "", "F", "file://host/#F"});
328 checkURL("file://host\\P", {"file", "", "", "host", 0, "/P", "", "", "file://host/P"});
329 checkURL("file://host\\?Q", {"file", "", "", "host", 0, "/", "Q", "", "file://host/?Q"});
330 checkURL("file://host\\../P", {"file", "", "", "host", 0, "/P", "", "", "file://host/P"});
331 checkURL("file://host\\/../P", {"file", "", "", "host", 0, "/P", "", "", "file://host/P"});
332 checkURL("file://host\\/P", {"file", "", "", "host", 0, "//P", "", "", "file://host//P"});
333 checkURL("http://host/A b", {"http", "", "", "host", 0, "/A%20b", "", "", "http://host/A%20b"});
334 checkURL("http://host/a%20B", {"http", "", "", "host", 0, "/a%20B", "", "", "http://host/a%20B"});
335 checkURL("http://host?q=@ <>!#fragment", {"http", "", "", "host", 0, "/", "q=@%20%3C%3E!", "fragment", "http://host/?q=@%20%3C%3E!#fragment"});
336 checkURL("http://user:@host", {"http", "user", "", "host", 0, "/", "", "", "http://user@host/"});
337 checkURL("http://user:@\thost", {"http", "user", "", "host", 0, "/", "", "", "http://user@host/"});
338 checkURL("http://user:\t@host", {"http", "user", "", "host", 0, "/", "", "", "http://user@host/"});
339 checkURL("http://user\t:@host", {"http", "user", "", "host", 0, "/", "", "", "http://user@host/"});
340 checkURL("http://use\tr:@host", {"http", "user", "", "host", 0, "/", "", "", "http://user@host/"});
341 checkURL("http://127.0.0.1:10100/path", {"http", "", "", "127.0.0.1", 10100, "/path", "", "", "http://127.0.0.1:10100/path"});
342 checkURL("http://127.0.0.1:/path", {"http", "", "", "127.0.0.1", 0, "/path", "", "", "http://127.0.0.1/path"});
343 checkURL("http://127.0.0.1\t:/path", {"http", "", "", "127.0.0.1", 0, "/path", "", "", "http://127.0.0.1/path"});
344 checkURL("http://127.0.0.1:\t/path", {"http", "", "", "127.0.0.1", 0, "/path", "", "", "http://127.0.0.1/path"});
345 checkURL("http://127.0.0.1:/\tpath", {"http", "", "", "127.0.0.1", 0, "/path", "", "", "http://127.0.0.1/path"});
346 checkURL("http://127.0.0.1:123", {"http", "", "", "127.0.0.1", 123, "/", "", "", "http://127.0.0.1:123/"});
347 checkURL("http://127.0.0.1:", {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"});
348 checkURL("http://[0:f::f:f:0:0]:123/path", {"http", "", "", "[0:f::f:f:0:0]", 123, "/path", "", "", "http://[0:f::f:f:0:0]:123/path"});
349 checkURL("http://[0:f::f:f:0:0]:123", {"http", "", "", "[0:f::f:f:0:0]", 123, "/", "", "", "http://[0:f::f:f:0:0]:123/"});
350 checkURL("http://[0:f:0:0:f:\t:]:123", {"http", "", "", "[0:f:0:0:f::]", 123, "/", "", "", "http://[0:f:0:0:f::]:123/"});
351 checkURL("http://[0:f:0:0:f::\t]:123", {"http", "", "", "[0:f:0:0:f::]", 123, "/", "", "", "http://[0:f:0:0:f::]:123/"});
352 checkURL("http://[0:f:0:0:f::]\t:123", {"http", "", "", "[0:f:0:0:f::]", 123, "/", "", "", "http://[0:f:0:0:f::]:123/"});
353 checkURL("http://[0:f:0:0:f::]:\t123", {"http", "", "", "[0:f:0:0:f::]", 123, "/", "", "", "http://[0:f:0:0:f::]:123/"});
354 checkURL("http://[0:f:0:0:f::]:1\t23", {"http", "", "", "[0:f:0:0:f::]", 123, "/", "", "", "http://[0:f:0:0:f::]:123/"});
355 checkURL("http://[0:f::f:f:0:0]:/path", {"http", "", "", "[0:f::f:f:0:0]", 0, "/path", "", "", "http://[0:f::f:f:0:0]/path"});
356 checkURL("http://[0:f::f:f:0:0]:", {"http", "", "", "[0:f::f:f:0:0]", 0, "/", "", "", "http://[0:f::f:f:0:0]/"});
357 checkURL("http://host:10100/path", {"http", "", "", "host", 10100, "/path", "", "", "http://host:10100/path"});
358 checkURL("http://host:/path", {"http", "", "", "host", 0, "/path", "", "", "http://host/path"});
359 checkURL("http://host:123", {"http", "", "", "host", 123, "/", "", "", "http://host:123/"});
360 checkURL("http://host:", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
361 checkURL("http://hos\tt\n:\t1\n2\t3\t/\npath", {"http", "", "", "host", 123, "/path", "", "", "http://host:123/path"});
362 checkURL("http://[email protected]/path3", {"http", "user", "", "example.org", 0, "/path3", "", "", "http://[email protected]/path3"});
363 checkURL("sc:/pa/pa", {"sc", "", "", "", 0, "/pa/pa", "", "", "sc:/pa/pa"});
364 checkURL("sc:/pa", {"sc", "", "", "", 0, "/pa", "", "", "sc:/pa"});
365 checkURL("sc:/pa/", {"sc", "", "", "", 0, "/pa/", "", "", "sc:/pa/"});
366 checkURL("notspecial:/notuser:notpassword@nothost", {"notspecial", "", "", "", 0, "/notuser:notpassword@nothost", "", "", "notspecial:/notuser:notpassword@nothost"});
367 checkURL("sc://pa/", {"sc", "", "", "pa", 0, "/", "", "", "sc://pa/"});
368 checkURL("sc://\tpa/", {"sc", "", "", "pa", 0, "/", "", "", "sc://pa/"});
369 checkURL("sc:/\t/pa/", {"sc", "", "", "pa", 0, "/", "", "", "sc://pa/"});
370 checkURL("sc:\t//pa/", {"sc", "", "", "pa", 0, "/", "", "", "sc://pa/"});
371 checkURL("http://host \a ", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
372 checkURL("notspecial:/a", {"notspecial", "", "", "", 0, "/a", "", "", "notspecial:/a"});
373 checkURL("notspecial:", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"});
374 checkURL("http:/a", {"http", "", "", "a", 0, "/", "", "", "http://a/"});
375 checkURL("http://256../", {"http", "", "", "256..", 0, "/", "", "", "http://256../"});
376 checkURL("http://256..", {"http", "", "", "256..", 0, "/", "", "", "http://256../"});
377 checkURL("http://127..1/", {"http", "", "", "127..1", 0, "/", "", "", "http://127..1/"});
378 checkURL("http://127.a.0.1/", {"http", "", "", "127.a.0.1", 0, "/", "", "", "http://127.a.0.1/"});
379 checkURL("http://127.0.0.1/", {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"});
380 checkURL("http://12\t7.0.0.1/", {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"});
381 checkURL("http://127.\t0.0.1/", {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"});
382 checkURL("http://./", {"http", "", "", ".", 0, "/", "", "", "http://./"});
383 checkURL("http://.", {"http", "", "", ".", 0, "/", "", "", "http://./"});
384 checkURL("notspecial:/a", {"notspecial", "", "", "", 0, "/a", "", "", "notspecial:/a"});
385 checkURL("notspecial:", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"});
386 checkURL("notspecial:/", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
387 checkURL("data:image/png;base64,encoded-data-follows-here", {"data", "", "", "", 0, "image/png;base64,encoded-data-follows-here", "", "", "data:image/png;base64,encoded-data-follows-here"});
388 checkURL("data:image/png;base64,encoded/data-with-slash", {"data", "", "", "", 0, "image/png;base64,encoded/data-with-slash", "", "", "data:image/png;base64,encoded/data-with-slash"});
389 checkURL("about:~", {"about", "", "", "", 0, "~", "", "", "about:~"});
390 checkURL("https://@test@test@example:800\\path@end", {"", "", "", "", 0, "", "", "", "https://@test@test@example:800\\path@end"});
391 checkURL("http://www.example.com/#a\nb\rc\td", {"http", "", "", "www.example.com", 0, "/", "", "abcd", "http://www.example.com/#abcd"});
392 checkURL("http://[A:b:c:DE:fF:0:1:aC]/", {"http", "", "", "[a:b:c:de:ff:0:1:ac]", 0, "/", "", "", "http://[a:b:c:de:ff:0:1:ac]/"});
393 checkURL("http:////////user:@webkit.org:99?foo", {"http", "user", "", "webkit.org", 99, "/", "foo", "", "http://[email protected]:99/?foo"});
394 checkURL("http:////////user:@webkit.org:99#foo", {"http", "user", "", "webkit.org", 99, "/", "", "foo", "http://[email protected]:99/#foo"});
395 checkURL("http:////\t////user:@webkit.org:99?foo", {"http", "user", "", "webkit.org", 99, "/", "foo", "", "http://[email protected]:99/?foo"});
396 checkURL("http://\t//\\///user:@webkit.org:99?foo", {"http", "user", "", "webkit.org", 99, "/", "foo", "", "http://[email protected]:99/?foo"});
397 checkURL("http:/\\user:@webkit.org:99?foo", {"http", "user", "", "webkit.org", 99, "/", "foo", "", "http://[email protected]:99/?foo"});
398 checkURL("http://127.0.0.1", {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"});
399 checkURLDifferences("http://127.0.0.1.",
400 {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"},
401 {"http", "", "", "127.0.0.1.", 0, "/", "", "", "http://127.0.0.1./"});
402 checkURLDifferences("http://127.0.0.1./",
403 {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"},
404 {"http", "", "", "127.0.0.1.", 0, "/", "", "", "http://127.0.0.1./"});
405 checkURL("http://127.0.0.1../", {"http", "", "", "127.0.0.1..", 0, "/", "", "", "http://127.0.0.1../"});
406 checkURLDifferences("http://0x100.0/",
407 {"", "", "", "", 0, "", "", "", "http://0x100.0/"},
408 {"http", "", "", "0x100.0", 0, "/", "", "", "http://0x100.0/"});
409 checkURLDifferences("http://0.0.0x100.0/",
410 {"", "", "", "", 0, "", "", "", "http://0.0.0x100.0/"},
411 {"http", "", "", "0.0.0x100.0", 0, "/", "", "", "http://0.0.0x100.0/"});
412 checkURLDifferences("http://0.0.0.0x100/",
413 {"", "", "", "", 0, "", "", "", "http://0.0.0.0x100/"},
414 {"http", "", "", "0.0.0.0x100", 0, "/", "", "", "http://0.0.0.0x100/"});
415 checkURL("http://host:123?", {"http", "", "", "host", 123, "/", "", "", "http://host:123/?"});
416 checkURL("http://host:123?query", {"http", "", "", "host", 123, "/", "query", "", "http://host:123/?query"});
417 checkURL("http://host:123#", {"http", "", "", "host", 123, "/", "", "", "http://host:123/#"});
418 checkURL("http://host:123#fragment", {"http", "", "", "host", 123, "/", "", "fragment", "http://host:123/#fragment"});
419 checkURLDifferences("foo:////",
420 {"foo", "", "", "", 0, "//", "", "", "foo:////"},
421 {"foo", "", "", "", 0, "////", "", "", "foo:////"});
422 checkURLDifferences("foo:///?",
423 {"foo", "", "", "", 0, "/", "", "", "foo:///?"},
424 {"foo", "", "", "", 0, "///", "", "", "foo:///?"});
425 checkURLDifferences("foo:///#",
426 {"foo", "", "", "", 0, "/", "", "", "foo:///#"},
427 {"foo", "", "", "", 0, "///", "", "", "foo:///#"});
428 checkURLDifferences("foo:///",
429 {"foo", "", "", "", 0, "/", "", "", "foo:///"},
430 {"foo", "", "", "", 0, "///", "", "", "foo:///"});
431 checkURLDifferences("foo://?",
432 {"foo", "", "", "", 0, "", "", "", "foo://?"},
433 {"foo", "", "", "", 0, "//", "", "", "foo://?"});
434 checkURLDifferences("foo://#",
435 {"foo", "", "", "", 0, "", "", "", "foo://#"},
436 {"foo", "", "", "", 0, "//", "", "", "foo://#"});
437 checkURLDifferences("foo://",
438 {"foo", "", "", "", 0, "", "", "", "foo://"},
439 {"foo", "", "", "", 0, "//", "", "", "foo://"});
440 checkURL("foo:/?", {"foo", "", "", "", 0, "/", "", "", "foo:/?"});
441 checkURL("foo:/#", {"foo", "", "", "", 0, "/", "", "", "foo:/#"});
442 checkURL("foo:/", {"foo", "", "", "", 0, "/", "", "", "foo:/"});
443 checkURL("foo:?", {"foo", "", "", "", 0, "", "", "", "foo:?"});
444 checkURL("foo:#", {"foo", "", "", "", 0, "", "", "", "foo:#"});
445 checkURLDifferences("A://",
446 {"a", "", "", "", 0, "", "", "", "a://"},
447 {"a", "", "", "", 0, "//", "", "", "a://"});
448 checkURLDifferences("aA://",
449 {"aa", "", "", "", 0, "", "", "", "aa://"},
450 {"aa", "", "", "", 0, "//", "", "", "aa://"});
451 checkURL(utf16String(u"foo://host/#ПП\u0007 a</"), {"foo", "", "", "host", 0, "/", "", "%D0%9F%D0%9F%07 a</", "foo://host/#%D0%9F%D0%9F%07 a</"});
452 checkURL(utf16String(u"foo://host/#\u0007 a</"), {"foo", "", "", "host", 0, "/", "", "%07 a</", "foo://host/#%07 a</"});
453 checkURL(utf16String(u"http://host?ß😍#ß😍"), {"http", "", "", "host", 0, "/", "%C3%9F%F0%9F%98%8D", "%C3%9F%F0%9F%98%8D", "http://host/?%C3%9F%F0%9F%98%8D#%C3%9F%F0%9F%98%8D"}, testTabsValueForSurrogatePairs);
454 checkURL(utf16String(u"http://host/path#💩\t💩"), {"http", "", "", "host", 0, "/path", "", "%F0%9F%92%A9%F0%9F%92%A9", "http://host/path#%F0%9F%92%A9%F0%9F%92%A9"}, testTabsValueForSurrogatePairs);
455 checkURL(utf16String(u"http://host/#ПП\u0007 a</"), {"http", "", "", "host", 0, "/", "", "%D0%9F%D0%9F%07 a</", "http://host/#%D0%9F%D0%9F%07 a</"});
456 checkURL(utf16String(u"http://host/#\u0007 a</"), {"http", "", "", "host", 0, "/", "", "%07 a</", "http://host/#%07 a</"});
457
458 // This disagrees with the web platform test for http://:@www.example.com but agrees with Chrome and URL::parse,
459 // and Firefox fails the web platform test differently. Maybe the web platform test ought to be changed.
460 checkURL("http://:@host", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
461}
462
463static void testUserPass(const String& value, const String& decoded, const String& encoded)
464{
465 URL userURL(URL(), makeString("http://", value, "@example.com/"));
466 URL passURL(URL(), makeString("http://user:", value, "@example.com/"));
467 EXPECT_EQ(encoded, userURL.encodedUser());
468 EXPECT_EQ(encoded, passURL.encodedPass());
469 EXPECT_EQ(decoded, userURL.user());
470 EXPECT_EQ(decoded, passURL.pass());
471}
472
473static void testUserPass(const String& value, const String& encoded)
474{
475 testUserPass(value, value, encoded);
476}
477
478TEST_F(WTF_URLParser, Credentials)
479{
480 auto validSurrogate = utf16String<3>({0xD800, 0xDD55, '\0'});
481 auto invalidSurrogate = utf16String<3>({0xD800, 'A', '\0'});
482 auto replacementA = utf16String<3>({0xFFFD, 'A', '\0'});
483
484 testUserPass("a", "a");
485 testUserPass("%", "%");
486 testUserPass("%25", "%", "%25");
487 testUserPass("%2525", "%25", "%2525");
488 testUserPass("%FX", "%FX");
489 testUserPass("%00", String::fromUTF8("\0", 1), "%00");
490 testUserPass("%F%25", "%F%", "%F%25");
491 testUserPass("%X%25", "%X%", "%X%25");
492 testUserPass("%%25", "%%", "%%25");
493 testUserPass("💩", "%C3%B0%C2%9F%C2%92%C2%A9");
494 testUserPass("%💩", "%%C3%B0%C2%9F%C2%92%C2%A9");
495 testUserPass(validSurrogate, "%F0%90%85%95");
496 testUserPass(replacementA, "%EF%BF%BDA");
497 testUserPass(invalidSurrogate, replacementA, "%EF%BF%BDA");
498}
499
500TEST_F(WTF_URLParser, ParseRelative)
501{
502 checkRelativeURL("/index.html", "http://webkit.org/path1/path2/", {"http", "", "", "webkit.org", 0, "/index.html", "", "", "http://webkit.org/index.html"});
503 checkRelativeURL("http://whatwg.org/index.html", "http://webkit.org/path1/path2/", {"http", "", "", "whatwg.org", 0, "/index.html", "", "", "http://whatwg.org/index.html"});
504 checkRelativeURL("index.html", "http://webkit.org/path1/path2/page.html?query#fragment", {"http", "", "", "webkit.org", 0, "/path1/path2/index.html", "", "", "http://webkit.org/path1/path2/index.html"});
505 checkRelativeURL("//whatwg.org/index.html", "https://www.webkit.org/path", {"https", "", "", "whatwg.org", 0, "/index.html", "", "", "https://whatwg.org/index.html"});
506 checkRelativeURL("http://example\t.\norg", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/", "", "", "http://example.org/"});
507 checkRelativeURL("test", "file:///path1/path2", {"file", "", "", "", 0, "/path1/test", "", "", "file:///path1/test"});
508 checkRelativeURL(utf16String(u"http://www.foo。bar.com"), "http://other.com/", {"http", "", "", "www.foo.bar.com", 0, "/", "", "", "http://www.foo.bar.com/"});
509 checkRelativeURLDifferences(utf16String(u"sc://ñ.test/"), "about:blank",
510 {"sc", "", "", "%C3%B1.test", 0, "/", "", "", "sc://%C3%B1.test/"},
511 {"sc", "", "", "xn--ida.test", 0, "/", "", "", "sc://xn--ida.test/"});
512 checkRelativeURL("#fragment", "http://host/path", {"http", "", "", "host", 0, "/path", "", "fragment", "http://host/path#fragment"});
513 checkRelativeURL("#fragment", "file:///path", {"file", "", "", "", 0, "/path", "", "fragment", "file:///path#fragment"});
514 checkRelativeURL("#fragment", "file:///path#old", {"file", "", "", "", 0, "/path", "", "fragment", "file:///path#fragment"});
515 checkRelativeURL("#", "file:///path#old", {"file", "", "", "", 0, "/path", "", "", "file:///path#"});
516 checkRelativeURL(" ", "file:///path#old", {"file", "", "", "", 0, "/path", "", "", "file:///path"});
517 checkRelativeURL("#", "file:///path", {"file", "", "", "", 0, "/path", "", "", "file:///path#"});
518 checkRelativeURL("#", "file:///path?query", {"file", "", "", "", 0, "/path", "query", "", "file:///path?query#"});
519 checkRelativeURL("#", "file:///path?query#old", {"file", "", "", "", 0, "/path", "query", "", "file:///path?query#"});
520 checkRelativeURL("?query", "http://host/path", {"http", "", "", "host", 0, "/path", "query", "", "http://host/path?query"});
521 checkRelativeURL("?query#fragment", "http://host/path", {"http", "", "", "host", 0, "/path", "query", "fragment", "http://host/path?query#fragment"});
522 checkRelativeURL("?new", "file:///path?old#fragment", {"file", "", "", "", 0, "/path", "new", "", "file:///path?new"});
523 checkRelativeURL("?", "file:///path?old#fragment", {"file", "", "", "", 0, "/path", "", "", "file:///path?"});
524 checkRelativeURL("?", "file:///path", {"file", "", "", "", 0, "/path", "", "", "file:///path?"});
525 checkRelativeURL("?query", "file:///path", {"file", "", "", "", 0, "/path", "query", "", "file:///path?query"});
526 checkRelativeURL(utf16String(u"?β"), "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "%CE%B2", "", "http://example.org/foo/bar?%CE%B2"});
527 checkRelativeURL("?", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar?"});
528 checkRelativeURL("#", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar#"});
529 checkRelativeURL("?#", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar?#"});
530 checkRelativeURL("#?", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "?", "http://example.org/foo/bar#?"});
531 checkRelativeURL("/", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/", "", "", "http://example.org/"});
532 checkRelativeURL("http://@host", "about:blank", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
533 checkRelativeURL("http://:@host", "about:blank", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
534 checkRelativeURL("http://foo.com/\\@", "http://example.org/foo/bar", {"http", "", "", "foo.com", 0, "//@", "", "", "http://foo.com//@"});
535 checkRelativeURL("\\@", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/@", "", "", "http://example.org/@"});
536 checkRelativeURL("/path3", "http://[email protected]/path1/path2", {"http", "user", "", "example.org", 0, "/path3", "", "", "http://[email protected]/path3"});
537 checkRelativeURL("", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar"});
538 checkRelativeURL("\t", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar"});
539 checkRelativeURL(" ", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar"});
540 checkRelativeURL(" \a \t\n", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar"});
541 checkRelativeURL(":foo.com\\", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/:foo.com/", "", "", "http://example.org/foo/:foo.com/"});
542 checkRelativeURL("http:/example.com/", "about:blank", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
543 checkRelativeURL("http:example.com/", "about:blank", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
544 checkRelativeURL("http:\\\\foo.com\\", "http://example.org/foo/bar", {"http", "", "", "foo.com", 0, "/", "", "", "http://foo.com/"});
545 checkRelativeURL("http:\\\\foo.com/", "http://example.org/foo/bar", {"http", "", "", "foo.com", 0, "/", "", "", "http://foo.com/"});
546 checkRelativeURL("http:\\\\foo.com", "http://example.org/foo/bar", {"http", "", "", "foo.com", 0, "/", "", "", "http://foo.com/"});
547 checkRelativeURL("http://ExAmPlE.CoM", "http://other.com", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
548 checkRelativeURL("http:", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar"});
549 checkRelativeURL("#x", "data:,", {"data", "", "", "", 0, ",", "", "x", "data:,#x"});
550 checkRelativeURL("#x", "about:blank", {"about", "", "", "", 0, "blank", "", "x", "about:blank#x"});
551 checkRelativeURL(" foo.com ", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/foo.com", "", "", "http://example.org/foo/foo.com"});
552 checkRelativeURL(" \a baz", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/baz", "", "", "http://example.org/foo/baz"});
553 checkRelativeURL("~", "http://example.org", {"http", "", "", "example.org", 0, "/~", "", "", "http://example.org/~"});
554 checkRelativeURL("notspecial:", "about:blank", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"});
555 checkRelativeURL("notspecial:", "http://host", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"});
556 checkRelativeURL("http:", "http://host", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
557 checkRelativeURL("i", "sc:/pa/po", {"sc", "", "", "", 0, "/pa/i", "", "", "sc:/pa/i"});
558 checkRelativeURL("i ", "sc:/pa/po", {"sc", "", "", "", 0, "/pa/i", "", "", "sc:/pa/i"});
559 checkRelativeURL("i\t\n ", "sc:/pa/po", {"sc", "", "", "", 0, "/pa/i", "", "", "sc:/pa/i"});
560 checkRelativeURL("i", "sc://ho/pa", {"sc", "", "", "ho", 0, "/i", "", "", "sc://ho/i"});
561 checkRelativeURL("!", "sc://ho/pa", {"sc", "", "", "ho", 0, "/!", "", "", "sc://ho/!"});
562 checkRelativeURL("!", "sc:/ho/pa", {"sc", "", "", "", 0, "/ho/!", "", "", "sc:/ho/!"});
563 checkRelativeURL("notspecial:/", "about:blank", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
564 checkRelativeURL("notspecial:/", "http://host", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
565 checkRelativeURL("foo:/", "http://example.org/foo/bar", {"foo", "", "", "", 0, "/", "", "", "foo:/"});
566 checkRelativeURL("://:0/", "http://webkit.org/", {"http", "", "", "webkit.org", 0, "/://:0/", "", "", "http://webkit.org/://:0/"});
567 checkRelativeURL(String(), "http://webkit.org/", {"http", "", "", "webkit.org", 0, "/", "", "", "http://webkit.org/"});
568 checkRelativeURL("https://@test@test@example:800\\path@end", "http://doesnotmatter/", {"", "", "", "", 0, "", "", "", "https://@test@test@example:800\\path@end"});
569 checkRelativeURL("http://f:0/c", "http://example.org/foo/bar", {"http", "", "", "f", 0, "/c", "", "", "http://f:0/c"});
570 checkRelativeURL(String(), "http://host/#fragment", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
571 checkRelativeURL("", "http://host/#fragment", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
572 checkRelativeURL(" ", "http://host/#fragment", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
573 checkRelativeURL(" ", "http://host/path?query#fra#gment", {"http", "", "", "host", 0, "/path", "query", "", "http://host/path?query"});
574 checkRelativeURL(" \a ", "http://host/#fragment", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
575 checkRelativeURLDifferences("foo://", "http://example.org/foo/bar",
576 {"foo", "", "", "", 0, "", "", "", "foo://"},
577 {"foo", "", "", "", 0, "//", "", "", "foo://"});
578 checkRelativeURL(utf16String(u"#β"), "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "%CE%B2", "http://example.org/foo/bar#%CE%B2"});
579 checkRelativeURL("index.html", "applewebdata://Host/", {"applewebdata", "", "", "Host", 0, "/index.html", "", "", "applewebdata://Host/index.html"});
580 checkRelativeURL("index.html", "applewebdata://Host", {"applewebdata", "", "", "Host", 0, "/index.html", "", "", "applewebdata://Host/index.html"});
581 checkRelativeURL("", "applewebdata://Host", {"applewebdata", "", "", "Host", 0, "", "", "", "applewebdata://Host"});
582 checkRelativeURL("?query", "applewebdata://Host", {"applewebdata", "", "", "Host", 0, "", "query", "", "applewebdata://Host?query"});
583 checkRelativeURL("#fragment", "applewebdata://Host", {"applewebdata", "", "", "Host", 0, "", "", "fragment", "applewebdata://Host#fragment"});
584 checkRelativeURL("notspecial://something?", "file:////var//containers//stuff/", {"notspecial", "", "", "something", 0, "", "", "", "notspecial://something?"}, TestTabs::No);
585 checkRelativeURL("notspecial://something#", "file:////var//containers//stuff/", {"notspecial", "", "", "something", 0, "", "", "", "notspecial://something#"}, TestTabs::No);
586 checkRelativeURL("http://something?", "file:////var//containers//stuff/", {"http", "", "", "something", 0, "/", "", "", "http://something/?"}, TestTabs::No);
587 checkRelativeURL("http://something#", "file:////var//containers//stuff/", {"http", "", "", "something", 0, "/", "", "", "http://something/#"}, TestTabs::No);
588 checkRelativeURL("file:", "file:///path?query#fragment", {"file", "", "", "", 0, "/path", "query", "", "file:///path?query"});
589 checkRelativeURL("/", "file:///C:/a/b", {"file", "", "", "", 0, "/C:/", "", "", "file:///C:/"});
590 checkRelativeURL("/abc", "file:///C:/a/b", {"file", "", "", "", 0, "/C:/abc", "", "", "file:///C:/abc"});
591 checkRelativeURL("/abc", "file:///C:", {"file", "", "", "", 0, "/C:/abc", "", "", "file:///C:/abc"});
592 checkRelativeURL("/abc", "file:///", {"file", "", "", "", 0, "/abc", "", "", "file:///abc"});
593 checkRelativeURL("//d:", "file:///C:/a/b", {"file", "", "", "", 0, "/d:", "", "", "file:///d:"}, TestTabs::No);
594 checkRelativeURL("//d|", "file:///C:/a/b", {"file", "", "", "", 0, "/d:", "", "", "file:///d:"}, TestTabs::No);
595 checkRelativeURL("//A|", "file:///C:/a/b", {"file", "", "", "", 0, "/A:", "", "", "file:///A:"}, TestTabs::No);
596
597 // The checking of slashes in SpecialAuthoritySlashes needed to get this to pass contradicts what is in the spec,
598 // but it is included in the web platform tests.
599 checkRelativeURL("http:\\\\host\\foo", "about:blank", {"http", "", "", "host", 0, "/foo", "", "", "http://host/foo"});
600}
601
602// These are differences between the new URLParser and the old URL::parse which make URLParser more standards compliant.
603TEST_F(WTF_URLParser, ParserDifferences)
604{
605 checkURLDifferences("http://127.0.1",
606 {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"},
607 {"http", "", "", "127.0.1", 0, "/", "", "", "http://127.0.1/"});
608 checkURLDifferences("http://011.11.0X11.0x011",
609 {"http", "", "", "9.11.17.17", 0, "/", "", "", "http://9.11.17.17/"},
610 {"http", "", "", "011.11.0x11.0x011", 0, "/", "", "", "http://011.11.0x11.0x011/"});
611 checkURLDifferences("http://[1234:0078:90AB:CdEf:0123:0007:89AB:0000]",
612 {"http", "", "", "[1234:78:90ab:cdef:123:7:89ab:0]", 0, "/", "", "", "http://[1234:78:90ab:cdef:123:7:89ab:0]/"},
613 {"http", "", "", "[1234:0078:90ab:cdef:0123:0007:89ab:0000]", 0, "/", "", "", "http://[1234:0078:90ab:cdef:0123:0007:89ab:0000]/"});
614 checkURLDifferences("http://[0:f:0:0:f:f:0:0]",
615 {"http", "", "", "[0:f::f:f:0:0]", 0, "/", "", "", "http://[0:f::f:f:0:0]/"},
616 {"http", "", "", "[0:f:0:0:f:f:0:0]", 0, "/", "", "", "http://[0:f:0:0:f:f:0:0]/"});
617 checkURLDifferences("http://[0:f:0:0:f:0:0:0]",
618 {"http", "", "", "[0:f:0:0:f::]", 0, "/", "", "", "http://[0:f:0:0:f::]/"},
619 {"http", "", "", "[0:f:0:0:f:0:0:0]", 0, "/", "", "", "http://[0:f:0:0:f:0:0:0]/"});
620 checkURLDifferences("http://[0:0:f:0:0:f:0:0]",
621 {"http", "", "", "[::f:0:0:f:0:0]", 0, "/", "", "", "http://[::f:0:0:f:0:0]/"},
622 {"http", "", "", "[0:0:f:0:0:f:0:0]", 0, "/", "", "", "http://[0:0:f:0:0:f:0:0]/"});
623 checkURLDifferences("http://[a:0:0:0:b:c::d]",
624 {"http", "", "", "[a::b:c:0:d]", 0, "/", "", "", "http://[a::b:c:0:d]/"},
625 {"http", "", "", "[a:0:0:0:b:c::d]", 0, "/", "", "", "http://[a:0:0:0:b:c::d]/"});
626 checkURLDifferences("http://[::7f00:0001]/",
627 {"http", "", "", "[::7f00:1]", 0, "/", "", "", "http://[::7f00:1]/"},
628 {"http", "", "", "[::7f00:0001]", 0, "/", "", "", "http://[::7f00:0001]/"});
629 checkURLDifferences("http://[::7f00:00]/",
630 {"http", "", "", "[::7f00:0]", 0, "/", "", "", "http://[::7f00:0]/"},
631 {"http", "", "", "[::7f00:00]", 0, "/", "", "", "http://[::7f00:00]/"});
632 checkURLDifferences("http://[::0:7f00:0001]/",
633 {"http", "", "", "[::7f00:1]", 0, "/", "", "", "http://[::7f00:1]/"},
634 {"http", "", "", "[::0:7f00:0001]", 0, "/", "", "", "http://[::0:7f00:0001]/"});
635 checkURLDifferences("http://127.00.0.1/",
636 {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"},
637 {"http", "", "", "127.00.0.1", 0, "/", "", "", "http://127.00.0.1/"});
638 checkURLDifferences("http://127.0.0.01/",
639 {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"},
640 {"http", "", "", "127.0.0.01", 0, "/", "", "", "http://127.0.0.01/"});
641 checkURLDifferences("http://example.com/path1/.%2e",
642 {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"},
643 {"http", "", "", "example.com", 0, "/path1/.%2e", "", "", "http://example.com/path1/.%2e"});
644 checkURLDifferences("http://example.com/path1/.%2E",
645 {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"},
646 {"http", "", "", "example.com", 0, "/path1/.%2E", "", "", "http://example.com/path1/.%2E"});
647 checkURLDifferences("http://example.com/path1/.%2E/",
648 {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"},
649 {"http", "", "", "example.com", 0, "/path1/.%2E/", "", "", "http://example.com/path1/.%2E/"});
650 checkURLDifferences("http://example.com/path1/%2e.",
651 {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"},
652 {"http", "", "", "example.com", 0, "/path1/%2e.", "", "", "http://example.com/path1/%2e."});
653 checkURLDifferences("http://example.com/path1/%2E%2e",
654 {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"},
655 {"http", "", "", "example.com", 0, "/path1/%2E%2e", "", "", "http://example.com/path1/%2E%2e"});
656 checkURLDifferences("http://example.com/path1/%2e",
657 {"http", "", "", "example.com", 0, "/path1/", "", "", "http://example.com/path1/"},
658 {"http", "", "", "example.com", 0, "/path1/%2e", "", "", "http://example.com/path1/%2e"});
659 checkURLDifferences("http://example.com/path1/%2E",
660 {"http", "", "", "example.com", 0, "/path1/", "", "", "http://example.com/path1/"},
661 {"http", "", "", "example.com", 0, "/path1/%2E", "", "", "http://example.com/path1/%2E"});
662 checkURLDifferences("http://example.com/path1/%2E/",
663 {"http", "", "", "example.com", 0, "/path1/", "", "", "http://example.com/path1/"},
664 {"http", "", "", "example.com", 0, "/path1/%2E/", "", "", "http://example.com/path1/%2E/"});
665 checkURLDifferences("http://example.com/path1/path2/%2e?query",
666 {"http", "", "", "example.com", 0, "/path1/path2/", "query", "", "http://example.com/path1/path2/?query"},
667 {"http", "", "", "example.com", 0, "/path1/path2/%2e", "query", "", "http://example.com/path1/path2/%2e?query"});
668 checkURLDifferences("http://example.com/path1/path2/%2e%2e?query",
669 {"http", "", "", "example.com", 0, "/path1/", "query", "", "http://example.com/path1/?query"},
670 {"http", "", "", "example.com", 0, "/path1/path2/%2e%2e", "query", "", "http://example.com/path1/path2/%2e%2e?query"});
671 checkURLDifferences("http://example.com/path1/path2/%2e#fragment",
672 {"http", "", "", "example.com", 0, "/path1/path2/", "", "fragment", "http://example.com/path1/path2/#fragment"},
673 {"http", "", "", "example.com", 0, "/path1/path2/%2e", "", "fragment", "http://example.com/path1/path2/%2e#fragment"});
674 checkURLDifferences("http://example.com/path1/path2/%2e%2e#fragment",
675 {"http", "", "", "example.com", 0, "/path1/", "", "fragment", "http://example.com/path1/#fragment"},
676 {"http", "", "", "example.com", 0, "/path1/path2/%2e%2e", "", "fragment", "http://example.com/path1/path2/%2e%2e#fragment"});
677 checkURL("http://example.com/path1/path2/A%2e%2e#fragment", {"http", "", "", "example.com", 0, "/path1/path2/A%2e%2e", "", "fragment", "http://example.com/path1/path2/A%2e%2e#fragment"});
678 checkURLDifferences("file://[0:a:0:0:b:c:0:0]/path",
679 {"file", "", "", "[0:a::b:c:0:0]", 0, "/path", "", "", "file://[0:a::b:c:0:0]/path"},
680 {"file", "", "", "[0:a:0:0:b:c:0:0]", 0, "/path", "", "", "file://[0:a:0:0:b:c:0:0]/path"});
681 checkURLDifferences("http://",
682 {"", "", "", "", 0, "", "", "", "http://"},
683 {"http", "", "", "", 0, "/", "", "", "http:/"});
684 checkRelativeURLDifferences("//", "https://www.webkit.org/path",
685 {"", "", "", "", 0, "", "", "", "//"},
686 {"https", "", "", "", 0, "/", "", "", "https:/"});
687 checkURLDifferences("http://127.0.0.1:65536/path",
688 {"", "", "", "", 0, "", "", "", "http://127.0.0.1:65536/path"},
689 {"http", "", "", "127.0.0.1", 0, "/path", "", "", "http://127.0.0.1:65536/path"});
690 checkURLDifferences("http://host:65536",
691 {"", "", "", "", 0, "", "", "", "http://host:65536"},
692 {"http", "", "", "host", 0, "/", "", "", "http://host:65536/"});
693 checkURLDifferences("http://127.0.0.1:65536",
694 {"", "", "", "", 0, "", "", "", "http://127.0.0.1:65536"},
695 {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1:65536/"});
696 checkURLDifferences("http://[0:f::f:f:0:0]:65536",
697 {"", "", "", "", 0, "", "", "", "http://[0:f::f:f:0:0]:65536"},
698 {"http", "", "", "[0:f::f:f:0:0]", 0, "/", "", "", "http://[0:f::f:f:0:0]:65536/"});
699 checkRelativeURLDifferences(":foo.com\\", "notspecial://example.org/foo/bar",
700 {"notspecial", "", "", "example.org", 0, "/foo/:foo.com\\", "", "", "notspecial://example.org/foo/:foo.com\\"},
701 {"notspecial", "", "", "example.org", 0, "/foo/:foo.com/", "", "", "notspecial://example.org/foo/:foo.com/"});
702 checkURL("sc://pa", {"sc", "", "", "pa", 0, "", "", "", "sc://pa"});
703 checkRelativeURLDifferences("notspecial:\\\\foo.com\\", "http://example.org/foo/bar",
704 {"notspecial", "", "", "", 0, "\\\\foo.com\\", "", "", "notspecial:\\\\foo.com\\"},
705 {"notspecial", "", "", "foo.com", 0, "/", "", "", "notspecial://foo.com/"});
706 checkRelativeURLDifferences("notspecial:\\\\foo.com/", "http://example.org/foo/bar",
707 {"notspecial", "", "", "", 0, "\\\\foo.com/", "", "", "notspecial:\\\\foo.com/"},
708 {"notspecial", "", "", "foo.com", 0, "/", "", "", "notspecial://foo.com/"});
709 checkRelativeURLDifferences("notspecial:\\\\foo.com", "http://example.org/foo/bar",
710 {"notspecial", "", "", "", 0, "\\\\foo.com", "", "", "notspecial:\\\\foo.com"},
711 {"notspecial", "", "", "foo.com", 0, "", "", "", "notspecial://foo.com"});
712 checkURLDifferences("file://notuser:notpassword@test",
713 {"", "", "", "", 0, "", "", "", "file://notuser:notpassword@test"},
714 {"file", "notuser", "notpassword", "test", 0, "/", "", "", "file://notuser:notpassword@test/"});
715 checkURLDifferences("file://notuser:notpassword@test/",
716 {"", "", "", "", 0, "", "", "", "file://notuser:notpassword@test/"},
717 {"file", "notuser", "notpassword", "test", 0, "/", "", "", "file://notuser:notpassword@test/"});
718 checkRelativeURLDifferences("http:/", "about:blank",
719 {"", "", "", "", 0, "", "", "", "http:/"},
720 {"http", "", "", "", 0, "/", "", "", "http:/"});
721 checkRelativeURLDifferences("http:", "about:blank",
722 {"http", "", "", "", 0, "", "", "", "http:"},
723 {"http", "", "", "", 0, "/", "", "", "http:/"});
724 checkRelativeURLDifferences("http:/", "http://host",
725 {"", "", "", "", 0, "", "", "", "http:/"},
726 {"http", "", "", "", 0, "/", "", "", "http:/"});
727 checkURLDifferences("http:/",
728 {"", "", "", "", 0, "", "", "", "http:/"},
729 {"http", "", "", "", 0, "/", "", "", "http:/"});
730 checkURLDifferences("http:",
731 {"http", "", "", "", 0, "", "", "", "http:"},
732 {"http", "", "", "", 0, "/", "", "", "http:/"});
733 checkRelativeURLDifferences("http:/example.com/", "http://example.org/foo/bar",
734 {"http", "", "", "example.org", 0, "/example.com/", "", "", "http://example.org/example.com/"},
735 {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
736
737 // This behavior matches Chrome and Firefox, but not WebKit using URL::parse.
738 // The behavior of URL::parse is clearly wrong because reparsing file://path would make path the host.
739 // The spec is unclear.
740 checkURLDifferences("file:path",
741 {"file", "", "", "", 0, "/path", "", "", "file:///path"},
742 {"file", "", "", "", 0, "path", "", "", "file://path"});
743 checkURLDifferences("file:pAtH",
744 {"file", "", "", "", 0, "/pAtH", "", "", "file:///pAtH"},
745 {"file", "", "", "", 0, "pAtH", "", "", "file://pAtH"});
746 checkURLDifferences("file:pAtH/",
747 {"file", "", "", "", 0, "/pAtH/", "", "", "file:///pAtH/"},
748 {"file", "", "", "", 0, "pAtH/", "", "", "file://pAtH/"});
749 checkURLDifferences("http://example.com%A0",
750 {"", "", "", "", 0, "", "", "", "http://example.com%A0"},
751 {"http", "", "", "example.com%a0", 0, "/", "", "", "http://example.com%a0/"});
752 checkURLDifferences("http://%E2%98%83",
753 {"http", "", "", "xn--n3h", 0, "/", "", "", "http://xn--n3h/"},
754 {"http", "", "", "%e2%98%83", 0, "/", "", "", "http://%e2%98%83/"});
755 checkURLDifferences("http://host%73",
756 {"http", "", "", "hosts", 0, "/", "", "", "http://hosts/"},
757 {"http", "", "", "host%73", 0, "/", "", "", "http://host%73/"});
758 checkURLDifferences("http://host%53",
759 {"http", "", "", "hosts", 0, "/", "", "", "http://hosts/"},
760 {"http", "", "", "host%53", 0, "/", "", "", "http://host%53/"});
761 checkURLDifferences("http://%",
762 {"", "", "", "", 0, "", "", "", "http://%"},
763 {"http", "", "", "%", 0, "/", "", "", "http://%/"});
764 checkURLDifferences("http://%7",
765 {"", "", "", "", 0, "", "", "", "http://%7"},
766 {"http", "", "", "%7", 0, "/", "", "", "http://%7/"});
767 checkURLDifferences("http://%7s",
768 {"", "", "", "", 0, "", "", "", "http://%7s"},
769 {"http", "", "", "%7s", 0, "/", "", "", "http://%7s/"});
770 checkURLDifferences("http://%73",
771 {"http", "", "", "s", 0, "/", "", "", "http://s/"},
772 {"http", "", "", "%73", 0, "/", "", "", "http://%73/"});
773 checkURLDifferences("http://abcdefg%",
774 {"", "", "", "", 0, "", "", "", "http://abcdefg%"},
775 {"http", "", "", "abcdefg%", 0, "/", "", "", "http://abcdefg%/"});
776 checkURLDifferences("http://abcd%7Xefg",
777 {"", "", "", "", 0, "", "", "", "http://abcd%7Xefg"},
778 {"http", "", "", "abcd%7xefg", 0, "/", "", "", "http://abcd%7xefg/"});
779
780
781 // URLParser matches Chrome and the spec, but not URL::parse or Firefox.
782 checkURLDifferences(utf16String(u"http://0Xc0.0250.01"),
783 {"http", "", "", "192.168.0.1", 0, "/", "", "", "http://192.168.0.1/"},
784 {"http", "", "", "0xc0.0250.01", 0, "/", "", "", "http://0xc0.0250.01/"});
785
786 checkURL("http://host/path%2e.%2E", {"http", "", "", "host", 0, "/path%2e.%2E", "", "", "http://host/path%2e.%2E"});
787
788 checkRelativeURLDifferences(utf16String(u"http://foo:💩@example.com/bar"), "http://other.com/",
789 {"http", "foo", utf16String(u"💩"), "example.com", 0, "/bar", "", "", "http://foo:%F0%9F%92%[email protected]/bar"},
790 {"", "", "", "", 0, "", "", "", utf16String(u"http://foo:💩@example.com/bar")}, testTabsValueForSurrogatePairs);
791 checkRelativeURLDifferences("http://&a:foo(b]c@d:2/", "http://example.org/foo/bar",
792 {"http", "&a", "foo(b]c", "d", 2, "/", "", "", "http://&a:foo(b%5Dc@d:2/"},
793 {"", "", "", "", 0, "", "", "", "http://&a:foo(b]c@d:2/"});
794 checkRelativeURLDifferences("http://`{}:`{}@h/`{}?`{}", "http://doesnotmatter/",
795 {"http", "`{}", "`{}", "h", 0, "/%60%7B%7D", "`{}", "", "http://%60%7B%7D:%60%7B%7D@h/%60%7B%7D?`{}"},
796 {"", "", "", "", 0, "", "", "", "http://`{}:`{}@h/`{}?`{}"});
797 checkURLDifferences("http://[0:f::f::f]",
798 {"", "", "", "", 0, "" , "", "", "http://[0:f::f::f]"},
799 {"http", "", "", "[0:f::f::f]", 0, "/" , "", "", "http://[0:f::f::f]/"});
800 checkURLDifferences("http://123",
801 {"http", "", "", "0.0.0.123", 0, "/", "", "", "http://0.0.0.123/"},
802 {"http", "", "", "123", 0, "/", "", "", "http://123/"});
803 checkURLDifferences("http://123.234/",
804 {"http", "", "", "123.0.0.234", 0, "/", "", "", "http://123.0.0.234/"},
805 {"http", "", "", "123.234", 0, "/", "", "", "http://123.234/"});
806 checkURLDifferences("http://123.234.012",
807 {"http", "", "", "123.234.0.10", 0, "/", "", "", "http://123.234.0.10/"},
808 {"http", "", "", "123.234.012", 0, "/", "", "", "http://123.234.012/"});
809 checkURLDifferences("http://123.234.12",
810 {"http", "", "", "123.234.0.12", 0, "/", "", "", "http://123.234.0.12/"},
811 {"http", "", "", "123.234.12", 0, "/", "", "", "http://123.234.12/"});
812 checkRelativeURLDifferences("file:c:\\foo\\bar.html", "file:///tmp/mock/path",
813 {"file", "", "", "", 0, "/c:/foo/bar.html", "", "", "file:///c:/foo/bar.html"},
814 {"file", "", "", "", 0, "/tmp/mock/c:/foo/bar.html", "", "", "file:///tmp/mock/c:/foo/bar.html"});
815 checkRelativeURLDifferences(" File:c|////foo\\bar.html", "file:///tmp/mock/path",
816 {"file", "", "", "", 0, "/c:////foo/bar.html", "", "", "file:///c:////foo/bar.html"},
817 {"file", "", "", "", 0, "/tmp/mock/c|////foo/bar.html", "", "", "file:///tmp/mock/c|////foo/bar.html"});
818 checkRelativeURLDifferences(" Fil\t\n\te\n\t\n:\t\n\tc\t\n\t|\n\t\n/\t\n\t/\n\t\n//foo\\bar.html", "file:///tmp/mock/path",
819 {"file", "", "", "", 0, "/c:////foo/bar.html", "", "", "file:///c:////foo/bar.html"},
820 {"file", "", "", "", 0, "/tmp/mock/c|////foo/bar.html", "", "", "file:///tmp/mock/c|////foo/bar.html"});
821 checkRelativeURLDifferences("C|/foo/bar", "file:///tmp/mock/path",
822 {"file", "", "", "", 0, "/C:/foo/bar", "", "", "file:///C:/foo/bar"},
823 {"file", "", "", "", 0, "/tmp/mock/C|/foo/bar", "", "", "file:///tmp/mock/C|/foo/bar"});
824 checkRelativeURLDifferences("/C|/foo/bar", "file:///tmp/mock/path",
825 {"file", "", "", "", 0, "/C:/foo/bar", "", "", "file:///C:/foo/bar"},
826 {"file", "", "", "", 0, "/C|/foo/bar", "", "", "file:///C|/foo/bar"});
827 checkRelativeURLDifferences("https://@test@test@example:800/", "http://doesnotmatter/",
828 {"https", "@test@test", "", "example", 800, "/", "", "", "https://%40test%40test@example:800/"},
829 {"", "", "", "", 0, "", "", "", "https://@test@test@example:800/"});
830 checkRelativeURLDifferences("https://@test@test@example:800/path@end", "http://doesnotmatter/",
831 {"https", "@test@test", "", "example", 800, "/path@end", "", "", "https://%40test%40test@example:800/path@end"},
832 {"", "", "", "", 0, "", "", "", "https://@test@test@example:800/path@end"});
833 checkURLDifferences("notspecial://@test@test@example:800/path@end",
834 {"notspecial", "@test@test", "", "example", 800, "/path@end", "", "", "notspecial://%40test%40test@example:800/path@end"},
835 {"", "", "", "", 0, "", "", "", "notspecial://@test@test@example:800/path@end"});
836 checkURLDifferences("notspecial://@test@test@example:800\\path@end",
837 {"notspecial", "@test@test@example", "800\\path", "end", 0, "", "", "", "notspecial://%40test%40test%40example:800%5Cpath@end"},
838 {"", "", "", "", 0, "", "", "", "notspecial://@test@test@example:800\\path@end"});
839 checkURLDifferences("http://%48OsT",
840 {"http", "", "", "host", 0, "/", "", "", "http://host/"},
841 {"http", "", "", "%48ost", 0, "/", "", "", "http://%48ost/"});
842 checkURLDifferences("http://h%4FsT",
843 {"http", "", "", "host", 0, "/", "", "", "http://host/"},
844 {"http", "", "", "h%4fst", 0, "/", "", "", "http://h%4fst/"});
845 checkURLDifferences("http://h%4fsT",
846 {"http", "", "", "host", 0, "/", "", "", "http://host/"},
847 {"http", "", "", "h%4fst", 0, "/", "", "", "http://h%4fst/"});
848 checkURLDifferences("http://h%6fsT",
849 {"http", "", "", "host", 0, "/", "", "", "http://host/"},
850 {"http", "", "", "h%6fst", 0, "/", "", "", "http://h%6fst/"});
851 checkURLDifferences("http://host/`",
852 {"http", "", "", "host", 0, "/%60", "", "", "http://host/%60"},
853 {"http", "", "", "host", 0, "/`", "", "", "http://host/`"});
854 checkURLDifferences("http://://",
855 {"", "", "", "", 0, "", "", "", "http://://"},
856 {"http", "", "", "", 0, "//", "", "", "http://://"});
857 checkURLDifferences("http://:123?",
858 {"", "", "", "", 0, "", "", "", "http://:123?"},
859 {"http", "", "", "", 123, "/", "", "", "http://:123/?"});
860 checkURLDifferences("http:/:",
861 {"", "", "", "", 0, "", "", "", "http:/:"},
862 {"http", "", "", "", 0, "/", "", "", "http://:/"});
863 checkURLDifferences("asdf://:",
864 {"", "", "", "", 0, "", "", "", "asdf://:"},
865 {"asdf", "", "", "", 0, "", "", "", "asdf://:"});
866 checkURLDifferences("http://:",
867 {"", "", "", "", 0, "", "", "", "http://:"},
868 {"http", "", "", "", 0, "/", "", "", "http://:/"});
869 checkURLDifferences("http:##foo",
870 {"", "", "", "", 0, "", "", "", "http:##foo"},
871 {"http", "", "", "", 0, "/", "", "#foo", "http:/##foo"});
872 checkURLDifferences("http:??bar",
873 {"", "", "", "", 0, "", "", "", "http:??bar"},
874 {"http", "", "", "", 0, "/", "?bar", "", "http:/??bar"});
875 checkURL("asdf:##foo", {"asdf", "", "", "", 0, "", "", "#foo", "asdf:##foo"});
876 checkURL("asdf:??bar", {"asdf", "", "", "", 0, "", "?bar", "", "asdf:??bar"});
877 checkRelativeURLDifferences("//C|/foo/bar", "file:///tmp/mock/path",
878 {"file", "", "", "", 0, "/C:/foo/bar", "", "", "file:///C:/foo/bar"},
879 {"", "", "", "", 0, "", "", "", "//C|/foo/bar"});
880 checkRelativeURLDifferences("//C:/foo/bar", "file:///tmp/mock/path",
881 {"file", "", "", "", 0, "/C:/foo/bar", "", "", "file:///C:/foo/bar"},
882 {"file", "", "", "c", 0, "/foo/bar", "", "", "file://c/foo/bar"});
883 checkRelativeURLDifferences("//C|?foo/bar", "file:///tmp/mock/path",
884 {"file", "", "", "", 0, "/C:/", "foo/bar", "", "file:///C:/?foo/bar"},
885 {"", "", "", "", 0, "", "", "", "//C|?foo/bar"});
886 checkRelativeURLDifferences("//C|#foo/bar", "file:///tmp/mock/path",
887 {"file", "", "", "", 0, "/C:/", "", "foo/bar", "file:///C:/#foo/bar"},
888 {"", "", "", "", 0, "", "", "", "//C|#foo/bar"});
889 checkURLDifferences("http://0xFFFFFfFF/",
890 {"http", "", "", "255.255.255.255", 0, "/", "", "", "http://255.255.255.255/"},
891 {"http", "", "", "0xffffffff", 0, "/", "", "", "http://0xffffffff/"});
892 checkURLDifferences("http://0000000000000000037777777777/",
893 {"http", "", "", "255.255.255.255", 0, "/", "", "", "http://255.255.255.255/"},
894 {"http", "", "", "0000000000000000037777777777", 0, "/", "", "", "http://0000000000000000037777777777/"});
895 checkURLDifferences("http://4294967295/",
896 {"http", "", "", "255.255.255.255", 0, "/", "", "", "http://255.255.255.255/"},
897 {"http", "", "", "4294967295", 0, "/", "", "", "http://4294967295/"});
898 checkURLDifferences("http://256/",
899 {"http", "", "", "0.0.1.0", 0, "/", "", "", "http://0.0.1.0/"},
900 {"http", "", "", "256", 0, "/", "", "", "http://256/"});
901 checkURLDifferences("http://256./",
902 {"http", "", "", "0.0.1.0", 0, "/", "", "", "http://0.0.1.0/"},
903 {"http", "", "", "256.", 0, "/", "", "", "http://256./"});
904 checkURLDifferences("http://123.256/",
905 {"http", "", "", "123.0.1.0", 0, "/", "", "", "http://123.0.1.0/"},
906 {"http", "", "", "123.256", 0, "/", "", "", "http://123.256/"});
907 checkURLDifferences("http://127.%.0.1/",
908 {"", "", "", "", 0, "", "", "", "http://127.%.0.1/"},
909 {"http", "", "", "127.%.0.1", 0, "/", "", "", "http://127.%.0.1/"});
910 checkURLDifferences("http://[1:2:3:4:5:6:7:8:]/",
911 {"", "", "", "", 0, "", "", "", "http://[1:2:3:4:5:6:7:8:]/"},
912 {"http", "", "", "[1:2:3:4:5:6:7:8:]", 0, "/", "", "", "http://[1:2:3:4:5:6:7:8:]/"});
913 checkURLDifferences("http://[:2:3:4:5:6:7:8:]/",
914 {"", "", "", "", 0, "", "", "", "http://[:2:3:4:5:6:7:8:]/"},
915 {"http", "", "", "[:2:3:4:5:6:7:8:]", 0, "/", "", "", "http://[:2:3:4:5:6:7:8:]/"});
916 checkURLDifferences("http://[1:2:3:4:5:6:7::]/",
917 {"http", "", "", "[1:2:3:4:5:6:7:0]", 0, "/", "", "", "http://[1:2:3:4:5:6:7:0]/"},
918 {"http", "", "", "[1:2:3:4:5:6:7::]", 0, "/", "", "", "http://[1:2:3:4:5:6:7::]/"});
919 checkURLDifferences("http://[1:2:3:4:5:6:7:::]/",
920 {"", "", "", "", 0, "", "", "", "http://[1:2:3:4:5:6:7:::]/"},
921 {"http", "", "", "[1:2:3:4:5:6:7:::]", 0, "/", "", "", "http://[1:2:3:4:5:6:7:::]/"});
922 checkURLDifferences("http://127.0.0.1~/",
923 {"http", "", "", "127.0.0.1~", 0, "/", "", "", "http://127.0.0.1~/"},
924 {"", "", "", "", 0, "", "", "", "http://127.0.0.1~/"});
925 checkURLDifferences("http://127.0.1~/",
926 {"http", "", "", "127.0.1~", 0, "/", "", "", "http://127.0.1~/"},
927 {"", "", "", "", 0, "", "", "", "http://127.0.1~/"});
928 checkURLDifferences("http://127.0.1./",
929 {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"},
930 {"http", "", "", "127.0.1.", 0, "/", "", "", "http://127.0.1./"});
931 checkURLDifferences("http://127.0.1.~/",
932 {"http", "", "", "127.0.1.~", 0, "/", "", "", "http://127.0.1.~/"},
933 {"", "", "", "", 0, "", "", "", "http://127.0.1.~/"});
934 checkURLDifferences("http://127.0.1.~",
935 {"http", "", "", "127.0.1.~", 0, "/", "", "", "http://127.0.1.~/"},
936 {"", "", "", "", 0, "", "", "", "http://127.0.1.~"});
937 checkRelativeURLDifferences("http://f:000/c", "http://example.org/foo/bar",
938 {"http", "", "", "f", 0, "/c", "", "", "http://f:0/c"},
939 {"http", "", "", "f", 0, "/c", "", "", "http://f:000/c"});
940 checkRelativeURLDifferences("http://f:010/c", "http://example.org/foo/bar",
941 {"http", "", "", "f", 10, "/c", "", "", "http://f:10/c"},
942 {"http", "", "", "f", 10, "/c", "", "", "http://f:010/c"});
943 checkURL("notspecial://HoSt", {"notspecial", "", "", "HoSt", 0, "", "", "", "notspecial://HoSt"});
944 checkURL("notspecial://H%6FSt", {"notspecial", "", "", "H%6FSt", 0, "", "", "", "notspecial://H%6FSt"});
945 checkURL("notspecial://H%4fSt", {"notspecial", "", "", "H%4fSt", 0, "", "", "", "notspecial://H%4fSt"});
946 checkURLDifferences(utf16String(u"notspecial://H😍ßt"),
947 {"notspecial", "", "", "H%F0%9F%98%8D%C3%9Ft", 0, "", "", "", "notspecial://H%F0%9F%98%8D%C3%9Ft"},
948 {"notspecial", "", "", "xn--hsst-qc83c", 0, "", "", "", "notspecial://xn--hsst-qc83c"}, testTabsValueForSurrogatePairs);
949 checkURLDifferences("http://[ffff:aaaa:cccc:eeee:bbbb:dddd:255.255.255.255]/",
950 {"http", "", "", "[ffff:aaaa:cccc:eeee:bbbb:dddd:ffff:ffff]", 0, "/", "", "", "http://[ffff:aaaa:cccc:eeee:bbbb:dddd:ffff:ffff]/"},
951 {"http", "", "", "[ffff:aaaa:cccc:eeee:bbbb:dddd:255.255.255.255]", 0, "/", "", "", "http://[ffff:aaaa:cccc:eeee:bbbb:dddd:255.255.255.255]/"}, TestTabs::No);
952 checkURLDifferences("http://[::123.234.12.210]/",
953 {"http", "", "", "[::7bea:cd2]", 0, "/", "", "", "http://[::7bea:cd2]/"},
954 {"http", "", "", "[::123.234.12.210]", 0, "/", "", "", "http://[::123.234.12.210]/"});
955 checkURLDifferences("http://[::a:255.255.255.255]/",
956 {"http", "", "", "[::a:ffff:ffff]", 0, "/", "", "", "http://[::a:ffff:ffff]/"},
957 {"http", "", "", "[::a:255.255.255.255]", 0, "/", "", "", "http://[::a:255.255.255.255]/"});
958 checkURLDifferences("http://[::0.00.255.255]/",
959 {"", "", "", "", 0, "", "", "", "http://[::0.00.255.255]/"},
960 {"http", "", "", "[::0.00.255.255]", 0, "/", "", "", "http://[::0.00.255.255]/"});
961 checkURLDifferences("http://[::0.0.255.255]/",
962 {"http", "", "", "[::ffff]", 0, "/", "", "", "http://[::ffff]/"},
963 {"http", "", "", "[::0.0.255.255]", 0, "/", "", "", "http://[::0.0.255.255]/"});
964 checkURLDifferences("http://[::0:1.0.255.255]/",
965 {"http", "", "", "[::100:ffff]", 0, "/", "", "", "http://[::100:ffff]/"},
966 {"http", "", "", "[::0:1.0.255.255]", 0, "/", "", "", "http://[::0:1.0.255.255]/"});
967 checkURLDifferences("http://[::A:1.0.255.255]/",
968 {"http", "", "", "[::a:100:ffff]", 0, "/", "", "", "http://[::a:100:ffff]/"},
969 {"http", "", "", "[::a:1.0.255.255]", 0, "/", "", "", "http://[::a:1.0.255.255]/"});
970 checkURLDifferences("http://[:127.0.0.1]",
971 {"", "", "", "", 0, "", "", "", "http://[:127.0.0.1]"},
972 {"http", "", "", "[:127.0.0.1]", 0, "/", "", "", "http://[:127.0.0.1]/"});
973 checkURLDifferences("http://[127.0.0.1]",
974 {"", "", "", "", 0, "", "", "", "http://[127.0.0.1]"},
975 {"http", "", "", "[127.0.0.1]", 0, "/", "", "", "http://[127.0.0.1]/"});
976 checkURLDifferences("http://[a:b:c:d:e:f:127.0.0.1]",
977 {"http", "", "", "[a:b:c:d:e:f:7f00:1]", 0, "/", "", "", "http://[a:b:c:d:e:f:7f00:1]/"},
978 {"http", "", "", "[a:b:c:d:e:f:127.0.0.1]", 0, "/", "", "", "http://[a:b:c:d:e:f:127.0.0.1]/"});
979 checkURLDifferences("http://[a:b:c:d:e:f:127.0.0.101]",
980 {"http", "", "", "[a:b:c:d:e:f:7f00:65]", 0, "/", "", "", "http://[a:b:c:d:e:f:7f00:65]/"},
981 {"http", "", "", "[a:b:c:d:e:f:127.0.0.101]", 0, "/", "", "", "http://[a:b:c:d:e:f:127.0.0.101]/"});
982 checkURLDifferences("http://[::a:b:c:d:e:f:127.0.0.1]",
983 {"", "", "", "", 0, "", "", "", "http://[::a:b:c:d:e:f:127.0.0.1]"},
984 {"http", "", "", "[::a:b:c:d:e:f:127.0.0.1]", 0, "/", "", "", "http://[::a:b:c:d:e:f:127.0.0.1]/"});
985 checkURLDifferences("http://[a:b::c:d:e:f:127.0.0.1]",
986 {"", "", "", "", 0, "", "", "", "http://[a:b::c:d:e:f:127.0.0.1]"},
987 {"http", "", "", "[a:b::c:d:e:f:127.0.0.1]", 0, "/", "", "", "http://[a:b::c:d:e:f:127.0.0.1]/"});
988 checkURLDifferences("http://[a:b:c:d:e:127.0.0.1]",
989 {"", "", "", "", 0, "", "", "", "http://[a:b:c:d:e:127.0.0.1]"},
990 {"http", "", "", "[a:b:c:d:e:127.0.0.1]", 0, "/", "", "", "http://[a:b:c:d:e:127.0.0.1]/"});
991 checkURLDifferences("http://[a:b:c:d:e:f:127.0.0.0.1]",
992 {"", "", "", "", 0, "", "", "", "http://[a:b:c:d:e:f:127.0.0.0.1]"},
993 {"http", "", "", "[a:b:c:d:e:f:127.0.0.0.1]", 0, "/", "", "", "http://[a:b:c:d:e:f:127.0.0.0.1]/"});
994 checkURLDifferences("http://[a:b:c:d:e:f:127.0.1]",
995 {"", "", "", "", 0, "", "", "", "http://[a:b:c:d:e:f:127.0.1]"},
996 {"http", "", "", "[a:b:c:d:e:f:127.0.1]", 0, "/", "", "", "http://[a:b:c:d:e:f:127.0.1]/"});
997 checkURLDifferences("http://[a:b:c:d:e:f:127.0.0.011]", // Chrome treats this as octal, Firefox and the spec fail
998 {"", "", "", "", 0, "", "", "", "http://[a:b:c:d:e:f:127.0.0.011]"},
999 {"http", "", "", "[a:b:c:d:e:f:127.0.0.011]", 0, "/", "", "", "http://[a:b:c:d:e:f:127.0.0.011]/"});
1000 checkURLDifferences("http://[a:b:c:d:e:f:127.0.00.1]",
1001 {"", "", "", "", 0, "", "", "", "http://[a:b:c:d:e:f:127.0.00.1]"},
1002 {"http", "", "", "[a:b:c:d:e:f:127.0.00.1]", 0, "/", "", "", "http://[a:b:c:d:e:f:127.0.00.1]/"});
1003 checkURLDifferences("http://[a:b:c:d:e:f:127.0.0.1.]",
1004 {"", "", "", "", 0, "", "", "", "http://[a:b:c:d:e:f:127.0.0.1.]"},
1005 {"http", "", "", "[a:b:c:d:e:f:127.0.0.1.]", 0, "/", "", "", "http://[a:b:c:d:e:f:127.0.0.1.]/"});
1006 checkURLDifferences("http://[a:b:c:d:e:f:127.0..0.1]",
1007 {"", "", "", "", 0, "", "", "", "http://[a:b:c:d:e:f:127.0..0.1]"},
1008 {"http", "", "", "[a:b:c:d:e:f:127.0..0.1]", 0, "/", "", "", "http://[a:b:c:d:e:f:127.0..0.1]/"});
1009 checkURLDifferences("http://[a:b:c:d:e:f::127.0.0.1]",
1010 {"", "", "", "", 0, "", "", "", "http://[a:b:c:d:e:f::127.0.0.1]"},
1011 {"http", "", "", "[a:b:c:d:e:f::127.0.0.1]", 0, "/", "", "", "http://[a:b:c:d:e:f::127.0.0.1]/"});
1012 checkURLDifferences("http://[a:b:c:d:e::127.0.0.1]",
1013 {"http", "", "", "[a:b:c:d:e:0:7f00:1]", 0, "/", "", "", "http://[a:b:c:d:e:0:7f00:1]/"},
1014 {"http", "", "", "[a:b:c:d:e::127.0.0.1]", 0, "/", "", "", "http://[a:b:c:d:e::127.0.0.1]/"});
1015 checkURLDifferences("http://[a:b:c:d::e:127.0.0.1]",
1016 {"http", "", "", "[a:b:c:d:0:e:7f00:1]", 0, "/", "", "", "http://[a:b:c:d:0:e:7f00:1]/"},
1017 {"http", "", "", "[a:b:c:d::e:127.0.0.1]", 0, "/", "", "", "http://[a:b:c:d::e:127.0.0.1]/"});
1018 checkURLDifferences("http://[a:b:c:d:e:f::127.0.0.]",
1019 {"", "", "", "", 0, "", "", "", "http://[a:b:c:d:e:f::127.0.0.]"},
1020 {"http", "", "", "[a:b:c:d:e:f::127.0.0.]", 0, "/", "", "", "http://[a:b:c:d:e:f::127.0.0.]/"});
1021 checkURLDifferences("http://[a:b:c:d:e:f::127.0.0.256]",
1022 {"", "", "", "", 0, "", "", "", "http://[a:b:c:d:e:f::127.0.0.256]"},
1023 {"http", "", "", "[a:b:c:d:e:f::127.0.0.256]", 0, "/", "", "", "http://[a:b:c:d:e:f::127.0.0.256]/"});
1024 checkURLDifferences("http://123456", {"http", "", "", "0.1.226.64", 0, "/", "", "", "http://0.1.226.64/"}, {"http", "", "", "123456", 0, "/", "", "", "http://123456/"});
1025 checkURL("asdf://123456", {"asdf", "", "", "123456", 0, "", "", "", "asdf://123456"});
1026 checkURLDifferences("http://[0:0:0:0:a:b:c:d]",
1027 {"http", "", "", "[::a:b:c:d]", 0, "/", "", "", "http://[::a:b:c:d]/"},
1028 {"http", "", "", "[0:0:0:0:a:b:c:d]", 0, "/", "", "", "http://[0:0:0:0:a:b:c:d]/"});
1029 checkURLDifferences("asdf://[0:0:0:0:a:b:c:d]",
1030 {"asdf", "", "", "[::a:b:c:d]", 0, "", "", "", "asdf://[::a:b:c:d]"},
1031 {"asdf", "", "", "[0:0:0:0:a:b:c:d]", 0, "", "", "", "asdf://[0:0:0:0:a:b:c:d]"}, TestTabs::No);
1032 shouldFail("a://%:a");
1033 checkURL("a://%:/", {"a", "", "", "%", 0, "/", "", "", "a://%/"});
1034 checkURL("a://%:", {"a", "", "", "%", 0, "", "", "", "a://%"});
1035 checkURL("a://%:1/", {"a", "", "", "%", 1, "/", "", "", "a://%:1/"});
1036 checkURLDifferences("http://%:",
1037 {"", "", "", "", 0, "", "", "", "http://%:"},
1038 {"http", "", "", "%", 0, "/", "", "", "http://%/"});
1039 checkURL("a://123456", {"a", "", "", "123456", 0, "", "", "", "a://123456"});
1040 checkURL("a://123456:7", {"a", "", "", "123456", 7, "", "", "", "a://123456:7"});
1041 checkURL("a://123456:7/", {"a", "", "", "123456", 7, "/", "", "", "a://123456:7/"});
1042 checkURL("a://A", {"a", "", "", "A", 0, "", "", "", "a://A"});
1043 checkURL("a://A:2", {"a", "", "", "A", 2, "", "", "", "a://A:2"});
1044 checkURL("a://A:2/", {"a", "", "", "A", 2, "/", "", "", "a://A:2/"});
1045 checkURLDifferences(u8"asd://ß",
1046 {"asd", "", "", "%C3%83%C2%9F", 0, "", "", "", "asd://%C3%83%C2%9F"},
1047 {"", "", "", "", 0, "", "", "", "about:blank"}, TestTabs::No);
1048 checkURLDifferences(u8"asd://ß:4",
1049 {"asd", "", "", "%C3%83%C2%9F", 4, "", "", "", "asd://%C3%83%C2%9F:4"},
1050 {"", "", "", "", 0, "", "", "", "about:blank"}, TestTabs::No);
1051 checkURLDifferences(u8"asd://ß:4/",
1052 {"asd", "", "", "%C3%83%C2%9F", 4, "/", "", "", "asd://%C3%83%C2%9F:4/"},
1053 {"", "", "", "", 0, "", "", "", "about:blank"}, TestTabs::No);
1054 checkURLDifferences("a://[A::b]:4",
1055 {"a", "", "", "[a::b]", 4, "", "", "", "a://[a::b]:4"},
1056 {"a", "", "", "[A::b]", 4, "", "", "", "a://[A::b]:4"});
1057 shouldFail("http://[~]");
1058 shouldFail("a://[~]");
1059 checkRelativeURLDifferences("a://b", "//[aBc]",
1060 {"a", "", "", "b", 0, "", "", "", "a://b"},
1061 {"", "", "", "", 0, "", "", "", "a://b"});
1062 checkURL(utf16String(u"http://öbb.at"), {"http", "", "", "xn--bb-eka.at", 0, "/", "", "", "http://xn--bb-eka.at/"});
1063 checkURL(utf16String(u"http://ÖBB.at"), {"http", "", "", "xn--bb-eka.at", 0, "/", "", "", "http://xn--bb-eka.at/"});
1064 checkURL(utf16String(u"http://√.com"), {"http", "", "", "xn--19g.com", 0, "/", "", "", "http://xn--19g.com/"});
1065 checkURLDifferences(utf16String(u"http://faß.de"),
1066 {"http", "", "", "xn--fa-hia.de", 0, "/", "", "", "http://xn--fa-hia.de/"},
1067 {"http", "", "", "fass.de", 0, "/", "", "", "http://fass.de/"});
1068 checkURL(utf16String(u"http://ԛәлп.com"), {"http", "", "", "xn--k1ai47bhi.com", 0, "/", "", "", "http://xn--k1ai47bhi.com/"});
1069 checkURLDifferences(utf16String(u"http://Ⱥbby.com"),
1070 {"http", "", "", "xn--bby-iy0b.com", 0, "/", "", "", "http://xn--bby-iy0b.com/"},
1071 {"http", "", "", "xn--bby-spb.com", 0, "/", "", "", "http://xn--bby-spb.com/"});
1072 checkURLDifferences(utf16String(u"http://\u2132"),
1073 {"", "", "", "", 0, "", "", "", utf16String(u"http://Ⅎ")},
1074 {"http", "", "", "xn--f3g", 0, "/", "", "", "http://xn--f3g/"});
1075 checkURLDifferences(utf16String(u"http://\u05D9\u05B4\u05D5\u05D0\u05B8/"),
1076 {"http", "", "", "xn--cdbi5etas", 0, "/", "", "", "http://xn--cdbi5etas/"},
1077 {"", "", "", "", 0, "", "", "", "about:blank"}, TestTabs::No);
1078 checkURLDifferences(utf16String(u"http://bidirectional\u0786\u07AE\u0782\u07B0\u0795\u07A9\u0793\u07A6\u0783\u07AA/"),
1079 {"", "", "", "", 0, "", "", "", utf16String(u"http://bidirectionalކޮންޕީޓަރު/")},
1080 {"", "", "", "", 0, "", "", "", "about:blank"}, TestTabs::No);
1081 checkURLDifferences(utf16String(u"http://contextj\u200D"),
1082 {"", "", "", "", 0, "", "", "", utf16String(u"http://contextj\u200D")},
1083 {"http", "", "", "contextj", 0, "/", "", "", "http://contextj/"});
1084 checkURL(utf16String(u"http://contexto\u30FB"), {"http", "", "", "xn--contexto-wg5g", 0, "/", "", "", "http://xn--contexto-wg5g/"});
1085 checkURLDifferences(utf16String(u"http://\u321D\u321E/"),
1086 {"http", "", "", "xn--()()-bs0sc174agx4b", 0, "/", "", "", "http://xn--()()-bs0sc174agx4b/"},
1087 {"http", "", "", "xn--5mkc", 0, "/", "", "", "http://xn--5mkc/"});
1088}
1089
1090TEST_F(WTF_URLParser, DefaultPort)
1091{
1092 checkURL("FtP://host:21/", {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"});
1093 checkURL("ftp://host:21/", {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"});
1094 checkURL("f\ttp://host:21/", {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"});
1095 checkURL("f\ttp://host\t:21/", {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"});
1096 checkURL("f\ttp://host:\t21/", {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"});
1097 checkURL("f\ttp://host:2\t1/", {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"});
1098 checkURL("f\ttp://host:21\t/", {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"});
1099 checkURL("ftp://host\t:21/", {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"});
1100 checkURL("ftp://host:\t21/", {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"});
1101 checkURL("ftp://host:2\t1/", {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"});
1102 checkURL("ftp://host:21\t/", {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"});
1103 checkURL("ftp://host:22/", {"ftp", "", "", "host", 22, "/", "", "", "ftp://host:22/"});
1104 checkURLDifferences("ftp://host:21",
1105 {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"},
1106 {"ftp", "", "", "host", 0, "", "", "", "ftp://host"});
1107 checkURLDifferences("ftp://host:22",
1108 {"ftp", "", "", "host", 22, "/", "", "", "ftp://host:22/"},
1109 {"ftp", "", "", "host", 22, "", "", "", "ftp://host:22"});
1110
1111 checkURL("gOpHeR://host:70/", {"gopher", "", "", "host", 0, "/", "", "", "gopher://host/"});
1112 checkURL("gopher://host:70/", {"gopher", "", "", "host", 0, "/", "", "", "gopher://host/"});
1113 checkURL("gopher://host:71/", {"gopher", "", "", "host", 71, "/", "", "", "gopher://host:71/"});
1114 // Spec, Chrome, Firefox, and URLParser have "/", URL::parse does not.
1115 // Spec, Chrome, URLParser, URL::parse recognize gopher default port, Firefox does not.
1116 checkURLDifferences("gopher://host:70",
1117 {"gopher", "", "", "host", 0, "/", "", "", "gopher://host/"},
1118 {"gopher", "", "", "host", 0, "", "", "", "gopher://host"});
1119 checkURLDifferences("gopher://host:71",
1120 {"gopher", "", "", "host", 71, "/", "", "", "gopher://host:71/"},
1121 {"gopher", "", "", "host", 71, "", "", "", "gopher://host:71"});
1122
1123 checkURL("hTtP://host:80", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
1124 checkURL("http://host:80", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
1125 checkURL("http://host:80/", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
1126 checkURL("http://host:81", {"http", "", "", "host", 81, "/", "", "", "http://host:81/"});
1127 checkURL("http://host:81/", {"http", "", "", "host", 81, "/", "", "", "http://host:81/"});
1128
1129 checkURL("hTtPs://host:443", {"https", "", "", "host", 0, "/", "", "", "https://host/"});
1130 checkURL("https://host:443", {"https", "", "", "host", 0, "/", "", "", "https://host/"});
1131 checkURL("https://host:443/", {"https", "", "", "host", 0, "/", "", "", "https://host/"});
1132 checkURL("https://host:444", {"https", "", "", "host", 444, "/", "", "", "https://host:444/"});
1133 checkURL("https://host:444/", {"https", "", "", "host", 444, "/", "", "", "https://host:444/"});
1134
1135 checkURL("wS://host:80/", {"ws", "", "", "host", 0, "/", "", "", "ws://host/"});
1136 checkURL("ws://host:80/", {"ws", "", "", "host", 0, "/", "", "", "ws://host/"});
1137 checkURL("ws://host:81/", {"ws", "", "", "host", 81, "/", "", "", "ws://host:81/"});
1138 // URLParser matches Chrome and Firefox, but not URL::parse
1139 checkURLDifferences("ws://host:80",
1140 {"ws", "", "", "host", 0, "/", "", "", "ws://host/"},
1141 {"ws", "", "", "host", 0, "", "", "", "ws://host"});
1142 checkURLDifferences("ws://host:81",
1143 {"ws", "", "", "host", 81, "/", "", "", "ws://host:81/"},
1144 {"ws", "", "", "host", 81, "", "", "", "ws://host:81"});
1145
1146 checkURL("WsS://host:443/", {"wss", "", "", "host", 0, "/", "", "", "wss://host/"});
1147 checkURL("wss://host:443/", {"wss", "", "", "host", 0, "/", "", "", "wss://host/"});
1148 checkURL("wss://host:444/", {"wss", "", "", "host", 444, "/", "", "", "wss://host:444/"});
1149 // URLParser matches Chrome and Firefox, but not URL::parse
1150 checkURLDifferences("wss://host:443",
1151 {"wss", "", "", "host", 0, "/", "", "", "wss://host/"},
1152 {"wss", "", "", "host", 0, "", "", "", "wss://host"});
1153 checkURLDifferences("wss://host:444",
1154 {"wss", "", "", "host", 444, "/", "", "", "wss://host:444/"},
1155 {"wss", "", "", "host", 444, "", "", "", "wss://host:444"});
1156
1157 checkURL("fTpS://host:990/", {"ftps", "", "", "host", 990, "/", "", "", "ftps://host:990/"});
1158 checkURL("ftps://host:990/", {"ftps", "", "", "host", 990, "/", "", "", "ftps://host:990/"});
1159 checkURL("ftps://host:991/", {"ftps", "", "", "host", 991, "/", "", "", "ftps://host:991/"});
1160 checkURL("ftps://host:990", {"ftps", "", "", "host", 990, "", "", "", "ftps://host:990"});
1161 checkURL("ftps://host:991", {"ftps", "", "", "host", 991, "", "", "", "ftps://host:991"});
1162
1163 checkURL("uNkNoWn://host:80/", {"unknown", "", "", "host", 80, "/", "", "", "unknown://host:80/"});
1164 checkURL("unknown://host:80/", {"unknown", "", "", "host", 80, "/", "", "", "unknown://host:80/"});
1165 checkURL("unknown://host:81/", {"unknown", "", "", "host", 81, "/", "", "", "unknown://host:81/"});
1166 checkURL("unknown://host:80", {"unknown", "", "", "host", 80, "", "", "", "unknown://host:80"});
1167 checkURL("unknown://host:81", {"unknown", "", "", "host", 81, "", "", "", "unknown://host:81"});
1168
1169 checkURL("file://host:0", {"file", "", "", "host", 0, "/", "", "", "file://host:0/"});
1170 checkURL("file://host:80", {"file", "", "", "host", 80, "/", "", "", "file://host:80/"});
1171 checkURL("file://host:80/path", {"file", "", "", "host", 80, "/path", "", "", "file://host:80/path"});
1172 checkURLDifferences("file://:80/path",
1173 {"", "", "", "", 0, "", "", "", "file://:80/path"},
1174 {"file", "", "", "", 80, "/path", "", "", "file://:80/path"});
1175 checkURLDifferences("file://:0/path",
1176 {"", "", "", "", 0, "", "", "", "file://:0/path"},
1177 {"file", "", "", "", 0, "/path", "", "", "file://:0/path"});
1178
1179 checkURL("http://example.com:0000000000000077", {"http", "", "", "example.com", 77, "/", "", "", "http://example.com:77/"});
1180 checkURL("http://example.com:0000000000000080", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
1181}
1182
1183TEST_F(WTF_URLParser, ParserFailures)
1184{
1185 shouldFail(" ");
1186 shouldFail(" \a ");
1187 shouldFail("");
1188 shouldFail(String());
1189 shouldFail("", "about:blank");
1190 shouldFail(String(), "about:blank");
1191 shouldFail("http://127.0.0.1:abc");
1192 shouldFail("http://host:abc");
1193 shouldFail("http://:abc");
1194 shouldFail("http://a:@", "about:blank");
1195 shouldFail("http://:b@", "about:blank");
1196 shouldFail("http://:@", "about:blank");
1197 shouldFail("http://a:@");
1198 shouldFail("http://:b@");
1199 shouldFail("http://@");
1200 shouldFail("http://[0:f::f:f:0:0]:abc");
1201 shouldFail("../i", "sc:sd");
1202 shouldFail("../i", "sc:sd/sd");
1203 shouldFail("/i", "sc:sd");
1204 shouldFail("/i", "sc:sd/sd");
1205 shouldFail("?i", "sc:sd");
1206 shouldFail("?i", "sc:sd/sd");
1207 shouldFail("http://example example.com", "http://other.com/");
1208 shouldFail("http://[www.example.com]/", "about:blank");
1209 shouldFail("http://192.168.0.1 hello", "http://other.com/");
1210 shouldFail("http://[example.com]", "http://other.com/");
1211 shouldFail("i", "sc:sd");
1212 shouldFail("i", "sc:sd/sd");
1213 shouldFail("i");
1214 shouldFail("asdf");
1215 shouldFail("~");
1216 shouldFail("%");
1217 shouldFail("//%");
1218 shouldFail("~", "about:blank");
1219 shouldFail("~~~");
1220 shouldFail("://:0/");
1221 shouldFail("://:0/", "");
1222 shouldFail("://:0/", "about:blank");
1223 shouldFail("about~");
1224 shouldFail("//C:asdf/foo/bar", "file:///tmp/mock/path");
1225 shouldFail("wss://[c::]abc/");
1226 shouldFail("abc://[c::]:abc/");
1227 shouldFail("abc://[c::]01");
1228 shouldFail("http://[1234::ab#]");
1229 shouldFail("http://[1234::ab/]");
1230 shouldFail("http://[1234::ab?]");
1231 shouldFail("http://[1234::ab@]");
1232 shouldFail("http://[1234::ab~]");
1233 shouldFail("http://[2001::1");
1234 shouldFail("http://4:b\xE1");
1235 shouldFail("http://[1:2:3:4:5:6:7:8~]/");
1236 shouldFail("http://[a:b:c:d:e:f:g:127.0.0.1]");
1237 shouldFail("http://[a:b:c:d:e:f:g:h:127.0.0.1]");
1238 shouldFail("http://[a:b:c:d:e:f:127.0.0.0x11]"); // Chrome treats this as hex, Firefox and the spec fail
1239 shouldFail("http://[a:b:c:d:e:f:127.0.-0.1]");
1240 shouldFail("asdf://space In\aHost");
1241 shouldFail("asdf://[0:0:0:0:a:b:c:d");
1242 shouldFail("http://[::0:0.0.00000.0]/");
1243}
1244
1245// These are in the spec but not in the web platform tests.
1246TEST_F(WTF_URLParser, AdditionalTests)
1247{
1248 checkURL("about:\a\aabc", {"about", "", "", "", 0, "%07%07abc", "", "", "about:%07%07abc"});
1249 checkURL("notspecial:\t\t\n\t", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"});
1250 checkURL("notspecial\t\t\n\t:\t\t\n\t/\t\t\n\t/\t\t\n\thost", {"notspecial", "", "", "host", 0, "", "", "", "notspecial://host"});
1251 checkRelativeURL("http:", "http://example.org/foo/bar?query#fragment", {"http", "", "", "example.org", 0, "/foo/bar", "query", "", "http://example.org/foo/bar?query"});
1252 checkRelativeURLDifferences("ws:", "http://example.org/foo/bar",
1253 {"ws", "", "", "", 0, "", "", "", "ws:"},
1254 {"ws", "", "", "", 0, "s:", "", "", "ws:s:"});
1255 checkRelativeURL("notspecial:", "http://example.org/foo/bar", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"});
1256
1257 const wchar_t surrogateBegin = 0xD800;
1258 const wchar_t validSurrogateEnd = 0xDD55;
1259 const wchar_t invalidSurrogateEnd = 'A';
1260 const wchar_t replacementCharacter = 0xFFFD;
1261 checkURL(utf16String<12>({'h', 't', 't', 'p', ':', '/', '/', 'w', '/', surrogateBegin, validSurrogateEnd, '\0'}),
1262 {"http", "", "", "w", 0, "/%F0%90%85%95", "", "", "http://w/%F0%90%85%95"}, testTabsValueForSurrogatePairs);
1263 shouldFail(utf16String<10>({'h', 't', 't', 'p', ':', '/', surrogateBegin, invalidSurrogateEnd, '/', '\0'}));
1264 shouldFail(utf16String<9>({'h', 't', 't', 'p', ':', '/', replacementCharacter, '/', '\0'}));
1265
1266 // URLParser matches Chrome and Firefox but not URL::parse.
1267 checkURLDifferences(utf16String<12>({'h', 't', 't', 'p', ':', '/', '/', 'w', '/', surrogateBegin, invalidSurrogateEnd}),
1268 {"http", "", "", "w", 0, "/%EF%BF%BDA", "", "", "http://w/%EF%BF%BDA"},
1269 {"http", "", "", "w", 0, "/%ED%A0%80A", "", "", "http://w/%ED%A0%80A"});
1270 checkURLDifferences(utf16String<13>({'h', 't', 't', 'p', ':', '/', '/', 'w', '/', '?', surrogateBegin, invalidSurrogateEnd, '\0'}),
1271 {"http", "", "", "w", 0, "/", "%EF%BF%BDA", "", "http://w/?%EF%BF%BDA"},
1272 {"http", "", "", "w", 0, "/", "%ED%A0%80A", "", "http://w/?%ED%A0%80A"});
1273 checkURLDifferences(utf16String<11>({'h', 't', 't', 'p', ':', '/', '/', 'w', '/', surrogateBegin, '\0'}),
1274 {"http", "", "", "w", 0, "/%EF%BF%BD", "", "", "http://w/%EF%BF%BD"},
1275 {"http", "", "", "w", 0, "/%ED%A0%80", "", "", "http://w/%ED%A0%80"});
1276 checkURLDifferences(utf16String<12>({'h', 't', 't', 'p', ':', '/', '/', 'w', '/', '?', surrogateBegin, '\0'}),
1277 {"http", "", "", "w", 0, "/", "%EF%BF%BD", "", "http://w/?%EF%BF%BD"},
1278 {"http", "", "", "w", 0, "/", "%ED%A0%80", "", "http://w/?%ED%A0%80"});
1279 checkURLDifferences(utf16String<13>({'h', 't', 't', 'p', ':', '/', '/', 'w', '/', '?', surrogateBegin, ' ', '\0'}),
1280 {"http", "", "", "w", 0, "/", "%EF%BF%BD", "", "http://w/?%EF%BF%BD"},
1281 {"http", "", "", "w", 0, "/", "%ED%A0%80", "", "http://w/?%ED%A0%80"});
1282
1283 // FIXME: Write more invalid surrogate pair tests based on feedback from https://bugs.webkit.org/show_bug.cgi?id=162105
1284}
1285
1286} // namespace TestWebKitAPI
1287