Skip to content

Commit 7773d58

Browse files
TimothyGudanielleadams
authored andcommitted
url: exit early when : delimiter is seen in hostname
This aligns with an upstream spec change. PR-URL: #38742 Fixes: #38710 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e9be209 commit 7773d58

10 files changed

+101
-54
lines changed

src/node_url.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1766,16 +1766,16 @@ void URL::Parse(const char* input,
17661766
url->flags |= URL_FLAGS_FAILED;
17671767
return;
17681768
}
1769+
if (state_override == kHostname) {
1770+
return;
1771+
}
17691772
url->flags |= URL_FLAGS_HAS_HOST;
17701773
if (!ParseHost(buffer, &url->host, special)) {
17711774
url->flags |= URL_FLAGS_FAILED;
17721775
return;
17731776
}
17741777
buffer.clear();
17751778
state = kPort;
1776-
if (state_override == kHostname) {
1777-
return;
1778-
}
17791779
} else if (ch == kEOL ||
17801780
ch == '/' ||
17811781
ch == '?' ||

test/fixtures/wpt/LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The 3-Clause BSD License
22

3-
Copyright 2019 web-platform-tests contributors
3+
Copyright © web-platform-tests contributors
44

55
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
66

test/fixtures/wpt/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Last update:
2121
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/5873f2d8f1/html/webappapis/timers
2222
- interfaces: https://github.com/web-platform-tests/wpt/tree/79fa4cf76e/interfaces
2323
- resources: https://github.com/web-platform-tests/wpt/tree/972ca5b669/resources
24-
- url: https://github.com/web-platform-tests/wpt/tree/1439087f27/url
24+
- url: https://github.com/web-platform-tests/wpt/tree/1fcb39223d/url
2525

2626
[Web Platform Tests]: https://github.com/web-platform-tests/wpt
2727
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/master/docs/git-node.md#git-node-wpt

test/fixtures/wpt/url/failure.html

+21-16
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,27 @@
2828
assert_throws_js(TypeError, () => url.href = test.input)
2929
}, "URL's href: " + name)
3030

31-
self.test(() => {
32-
const client = new XMLHttpRequest()
33-
assert_throws_dom("SyntaxError", () => client.open("GET", test.input))
34-
}, "XHR: " + name)
35-
36-
self.test(() => {
37-
assert_throws_js(TypeError, () => self.navigator.sendBeacon(test.input))
38-
}, "sendBeacon(): " + name)
39-
40-
self.test(() => {
41-
assert_throws_js(self[0].TypeError, () => self[0].location = test.input)
42-
}, "Location's href: " + name)
43-
44-
self.test(() => {
45-
assert_throws_dom("SyntaxError", () => self.open(test.input).close())
46-
}, "window.open(): " + name)
31+
// The following use cases resolve the URL input relative to the current
32+
// document's URL. If this test input could be construed as a valid URL
33+
// when resolved against a base URL, skip these cases.
34+
if (!test.inputCanBeRelative) {
35+
self.test(() => {
36+
const client = new XMLHttpRequest()
37+
assert_throws_dom("SyntaxError", () => client.open("GET", test.input))
38+
}, "XHR: " + name)
39+
40+
self.test(() => {
41+
assert_throws_js(TypeError, () => self.navigator.sendBeacon(test.input))
42+
}, "sendBeacon(): " + name)
43+
44+
self.test(() => {
45+
assert_throws_js(self[0].TypeError, () => self[0].location = test.input)
46+
}, "Location's href: " + name)
47+
48+
self.test(() => {
49+
assert_throws_dom("SyntaxError", () => self.open(test.input).close())
50+
}, "window.open(): " + name)
51+
}
4752
}
4853
}
4954
</script>

test/fixtures/wpt/url/resources/setters_tests.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -1153,24 +1153,24 @@
11531153
}
11541154
},
11551155
{
1156-
"comment": "Stuff after a : delimiter is ignored",
1156+
"comment": ": delimiter invalidates entire value",
11571157
"href": "http://example.net/path",
11581158
"new_value": "example.com:8080",
11591159
"expected": {
1160-
"href": "http://example.com/path",
1161-
"host": "example.com",
1162-
"hostname": "example.com",
1160+
"href": "http://example.net/path",
1161+
"host": "example.net",
1162+
"hostname": "example.net",
11631163
"port": ""
11641164
}
11651165
},
11661166
{
1167-
"comment": "Stuff after a : delimiter is ignored",
1167+
"comment": ": delimiter invalidates entire value",
11681168
"href": "http://example.net:8080/path",
11691169
"new_value": "example.com:",
11701170
"expected": {
1171-
"href": "http://example.com:8080/path",
1172-
"host": "example.com:8080",
1173-
"hostname": "example.com",
1171+
"href": "http://example.net:8080/path",
1172+
"host": "example.net:8080",
1173+
"hostname": "example.net",
11741174
"port": "8080"
11751175
}
11761176
},

test/fixtures/wpt/url/resources/urltestdata.json

+31-10
Original file line numberDiff line numberDiff line change
@@ -3156,7 +3156,8 @@
31563156
{
31573157
"input": "http:/:@/www.example.com",
31583158
"base": "about:blank",
3159-
"failure": true
3159+
"failure": true,
3160+
"inputCanBeRelative": true
31603161
},
31613162
{
31623163
"input": "http://user@/www.example.com",
@@ -3166,12 +3167,14 @@
31663167
{
31673168
"input": "http:@/www.example.com",
31683169
"base": "about:blank",
3169-
"failure": true
3170+
"failure": true,
3171+
"inputCanBeRelative": true
31703172
},
31713173
{
31723174
"input": "http:/@/www.example.com",
31733175
"base": "about:blank",
3174-
"failure": true
3176+
"failure": true,
3177+
"inputCanBeRelative": true
31753178
},
31763179
{
31773180
"input": "http://@/www.example.com",
@@ -3181,17 +3184,20 @@
31813184
{
31823185
"input": "https:@/www.example.com",
31833186
"base": "about:blank",
3184-
"failure": true
3187+
"failure": true,
3188+
"inputCanBeRelative": true
31853189
},
31863190
{
31873191
"input": "http:a:b@/www.example.com",
31883192
"base": "about:blank",
3189-
"failure": true
3193+
"failure": true,
3194+
"inputCanBeRelative": true
31903195
},
31913196
{
31923197
"input": "http:/a:b@/www.example.com",
31933198
"base": "about:blank",
3194-
"failure": true
3199+
"failure": true,
3200+
"inputCanBeRelative": true
31953201
},
31963202
{
31973203
"input": "http://a:b@/www.example.com",
@@ -3201,7 +3207,8 @@
32013207
{
32023208
"input": "http::@/www.example.com",
32033209
"base": "about:blank",
3204-
"failure": true
3210+
"failure": true,
3211+
"inputCanBeRelative": true
32053212
},
32063213
{
32073214
"input": "http:a:@www.example.com",
@@ -3645,6 +3652,17 @@
36453652
"search": "?%EF%BF%BD",
36463653
"hash": "#%EF%BF%BD"
36473654
},
3655+
"Domain is ASCII, but a label is invalid IDNA",
3656+
{
3657+
"input": "http://a.b.c.xn--pokxncvks",
3658+
"base": "about:blank",
3659+
"failure": true
3660+
},
3661+
{
3662+
"input": "http://10.0.0.xn--pokxncvks",
3663+
"base": "about:blank",
3664+
"failure": true
3665+
},
36483666
"Test name prepping, fullwidth input should be converted to ASCII and NOT IDN-ized. This is 'Go' in fullwidth UTF-8/UTF-16.",
36493667
{
36503668
"input": "http://Go.com",
@@ -7320,17 +7338,20 @@
73207338
{
73217339
"input": "a",
73227340
"base": "about:blank",
7323-
"failure": true
7341+
"failure": true,
7342+
"inputCanBeRelative": true
73247343
},
73257344
{
73267345
"input": "a/",
73277346
"base": "about:blank",
7328-
"failure": true
7347+
"failure": true,
7348+
"inputCanBeRelative": true
73297349
},
73307350
{
73317351
"input": "a//",
73327352
"base": "about:blank",
7333-
"failure": true
7353+
"failure": true,
7354+
"inputCanBeRelative": true
73347355
},
73357356
"Bases that don't fail to parse but fail to be bases",
73367357
{

test/fixtures/wpt/url/url-setters.html test/fixtures/wpt/url/url-setters-a-area.window.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
<!doctype html>
2-
<meta charset=utf-8>
3-
<script src=/resources/testharness.js></script>
4-
<script src=/resources/testharnessreport.js></script>
5-
<div id=log></div>
6-
<script>
1+
// Keep this file in sync with url-setters.any.js.
2+
73
promise_test(() => fetch("resources/setters_tests.json").then(res => res.json()).then(runURLSettersTests), "Loading data…");
84

95
function runURLSettersTests(all_test_cases) {
@@ -19,13 +15,6 @@
1915
if ("comment" in test_case) {
2016
name += " " + test_case.comment;
2117
}
22-
test(function() {
23-
var url = new URL(test_case.href);
24-
url[attribute_to_be_set] = test_case.new_value;
25-
for (var attribute in test_case.expected) {
26-
assert_equals(url[attribute], test_case.expected[attribute])
27-
}
28-
}, "URL: " + name)
2918
test(function() {
3019
var url = document.createElement("a");
3120
url.href = test_case.href;
@@ -45,4 +34,3 @@
4534
}
4635
}
4736
}
48-
</script>
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Keep this file in sync with url-setters-a-area.window.js.
2+
3+
promise_test(() => fetch("resources/setters_tests.json").then(res => res.json()).then(runURLSettersTests), "Loading data…");
4+
5+
function runURLSettersTests(all_test_cases) {
6+
for (var attribute_to_be_set in all_test_cases) {
7+
if (attribute_to_be_set == "comment") {
8+
continue;
9+
}
10+
var test_cases = all_test_cases[attribute_to_be_set];
11+
for(var i = 0, l = test_cases.length; i < l; i++) {
12+
var test_case = test_cases[i];
13+
var name = "Setting <" + test_case.href + ">." + attribute_to_be_set +
14+
" = '" + test_case.new_value + "'";
15+
if ("comment" in test_case) {
16+
name += " " + test_case.comment;
17+
}
18+
test(function() {
19+
var url = new URL(test_case.href);
20+
url[attribute_to_be_set] = test_case.new_value;
21+
for (var attribute in test_case.expected) {
22+
assert_equals(url[attribute], test_case.expected[attribute])
23+
}
24+
}, "URL: " + name)
25+
}
26+
}
27+
}

test/fixtures/wpt/versions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"path": "resources"
4545
},
4646
"url": {
47-
"commit": "1439087f27135b06deb70ffbf43e65ff64ff1ee6",
47+
"commit": "1fcb39223d3009fbb46c1b254755d6cc75e290f1",
4848
"path": "url"
4949
}
5050
}

test/wpt/status/url.json

+6
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,11 @@
2424
},
2525
"url-origin.any.js": {
2626
"requires": ["small-icu"]
27+
},
28+
"url-setters.any.js": {
29+
"requires": ["small-icu"]
30+
},
31+
"url-setters-a-area.window.js": {
32+
"skip": "already tested in url-setters.any.js"
2733
}
2834
}

0 commit comments

Comments
 (0)