Skip to content

Commit 514e3fd

Browse files
committed
url: prevent pathname setter from erasing path of path-only URLs
This change prevents the pathname setter from erasing the path of path-only URLs as that would make them cannot-be-a-base URLs. The changes done in all files except src/node_url.cc has been done by running: ```console git node wpt url ``` Fixes: #39059 Signed-off-by: Darshan Sen <[email protected]>
1 parent 38a15d8 commit 514e3fd

File tree

5 files changed

+286
-4
lines changed

5 files changed

+286
-4
lines changed

src/node_url.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,8 @@ void URL::Parse(const char* input,
14771477
if (ch != '/') {
14781478
continue;
14791479
}
1480+
} else if (has_state_override && url->host.empty()) {
1481+
url->path.emplace_back("");
14801482
}
14811483
break;
14821484
case kPath:

test/fixtures/wpt/README.md

Lines changed: 2 additions & 2 deletions
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/1fcb39223d/url
24+
- url: https://github.com/web-platform-tests/wpt/tree/41590413af/url
2525

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

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,26 @@
990990
"hostname": "test",
991991
"port": "12"
992992
}
993+
},
994+
{
995+
"comment": "Leading / is not stripped",
996+
"href": "http://example.com/",
997+
"new_value": "///bad.com",
998+
"expected": {
999+
"href": "http://example.com/",
1000+
"host": "example.com",
1001+
"hostname": "example.com"
1002+
}
1003+
},
1004+
{
1005+
"comment": "Leading / is not stripped",
1006+
"href": "sc://example.com/",
1007+
"new_value": "///bad.com",
1008+
"expected": {
1009+
"href": "sc:///",
1010+
"host": "",
1011+
"hostname": ""
1012+
}
9931013
}
9941014
],
9951015
"hostname": [
@@ -1345,6 +1365,26 @@
13451365
"hostname": "",
13461366
"pathname": "//p"
13471367
}
1368+
},
1369+
{
1370+
"comment": "Leading / is not stripped",
1371+
"href": "http://example.com/",
1372+
"new_value": "///bad.com",
1373+
"expected": {
1374+
"href": "http://example.com/",
1375+
"host": "example.com",
1376+
"hostname": "example.com"
1377+
}
1378+
},
1379+
{
1380+
"comment": "Leading / is not stripped",
1381+
"href": "sc://example.com/",
1382+
"new_value": "///bad.com",
1383+
"expected": {
1384+
"href": "sc:///",
1385+
"host": "",
1386+
"hostname": ""
1387+
}
13481388
}
13491389
],
13501390
"port": [
@@ -1667,6 +1707,24 @@
16671707
"pathname": "/%23"
16681708
}
16691709
},
1710+
{
1711+
"comment": "? doesn't mess up encoding",
1712+
"href": "http://example.net",
1713+
"new_value": "/?é",
1714+
"expected": {
1715+
"href": "http://example.net/%3F%C3%A9",
1716+
"pathname": "/%3F%C3%A9"
1717+
}
1718+
},
1719+
{
1720+
"comment": "# doesn't mess up encoding",
1721+
"href": "http://example.net",
1722+
"new_value": "/#é",
1723+
"expected": {
1724+
"href": "http://example.net/%23%C3%A9",
1725+
"pathname": "/%23%C3%A9"
1726+
}
1727+
},
16701728
{
16711729
"comment": "File URLs and (back)slashes",
16721730
"href": "file://monkey/",

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

Lines changed: 223 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,36 @@
539539
"search": "",
540540
"hash": ""
541541
},
542+
{
543+
"input": "\\x",
544+
"base": "http://example.org/foo/bar",
545+
"href": "http://example.org/x",
546+
"origin": "http://example.org",
547+
"protocol": "http:",
548+
"username": "",
549+
"password": "",
550+
"host": "example.org",
551+
"hostname": "example.org",
552+
"port": "",
553+
"pathname": "/x",
554+
"search": "",
555+
"hash": ""
556+
},
557+
{
558+
"input": "\\\\x\\hello",
559+
"base": "http://example.org/foo/bar",
560+
"href": "http://x/hello",
561+
"origin": "http://x",
562+
"protocol": "http:",
563+
"username": "",
564+
"password": "",
565+
"host": "x",
566+
"hostname": "x",
567+
"port": "",
568+
"pathname": "/hello",
569+
"search": "",
570+
"hash": ""
571+
},
542572
{
543573
"input": "::",
544574
"base": "http://example.org/foo/bar",
@@ -4698,6 +4728,140 @@
46984728
"base": "about:blank",
46994729
"failure": true
47004730
},
4731+
{
4732+
"input": "foo://ho\u0000st/",
4733+
"base": "about:blank",
4734+
"failure": true
4735+
},
4736+
{
4737+
"input": "foo://ho|st/",
4738+
"base": "about:blank",
4739+
"failure": true
4740+
},
4741+
"Forbidden host codepoints: tabs and newlines are removed during preprocessing",
4742+
{
4743+
"input": "foo://ho\u0009st/",
4744+
"base": "about:blank",
4745+
"hash": "",
4746+
"host": "host",
4747+
"hostname": "host",
4748+
"href":"foo://host/",
4749+
"password": "",
4750+
"pathname": "/",
4751+
"port":"",
4752+
"protocol": "foo:",
4753+
"search": "",
4754+
"username": ""
4755+
},
4756+
{
4757+
"input": "foo://ho\u000Ast/",
4758+
"base": "about:blank",
4759+
"hash": "",
4760+
"host": "host",
4761+
"hostname": "host",
4762+
"href":"foo://host/",
4763+
"password": "",
4764+
"pathname": "/",
4765+
"port":"",
4766+
"protocol": "foo:",
4767+
"search": "",
4768+
"username": ""
4769+
},
4770+
{
4771+
"input": "foo://ho\u000Dst/",
4772+
"base": "about:blank",
4773+
"hash": "",
4774+
"host": "host",
4775+
"hostname": "host",
4776+
"href":"foo://host/",
4777+
"password": "",
4778+
"pathname": "/",
4779+
"port":"",
4780+
"protocol": "foo:",
4781+
"search": "",
4782+
"username": ""
4783+
},
4784+
"Encoded forbidden host codepoints in special URLs",
4785+
{
4786+
"input": "http://ho%00st/",
4787+
"base": "about:blank",
4788+
"failure": true
4789+
},
4790+
{
4791+
"input": "http://ho%09st/",
4792+
"base": "about:blank",
4793+
"failure": true
4794+
},
4795+
{
4796+
"input": "http://ho%0Ast/",
4797+
"base": "about:blank",
4798+
"failure": true
4799+
},
4800+
{
4801+
"input": "http://ho%0Dst/",
4802+
"base": "about:blank",
4803+
"failure": true
4804+
},
4805+
{
4806+
"input": "http://ho%20st/",
4807+
"base": "about:blank",
4808+
"failure": true
4809+
},
4810+
{
4811+
"input": "http://ho%23st/",
4812+
"base": "about:blank",
4813+
"failure": true
4814+
},
4815+
{
4816+
"input": "http://ho%2Fst/",
4817+
"base": "about:blank",
4818+
"failure": true
4819+
},
4820+
{
4821+
"input": "http://ho%3Ast/",
4822+
"base": "about:blank",
4823+
"failure": true
4824+
},
4825+
{
4826+
"input": "http://ho%3Cst/",
4827+
"base": "about:blank",
4828+
"failure": true
4829+
},
4830+
{
4831+
"input": "http://ho%3Est/",
4832+
"base": "about:blank",
4833+
"failure": true
4834+
},
4835+
{
4836+
"input": "http://ho%3Fst/",
4837+
"base": "about:blank",
4838+
"failure": true
4839+
},
4840+
{
4841+
"input": "http://ho%40st/",
4842+
"base": "about:blank",
4843+
"failure": true
4844+
},
4845+
{
4846+
"input": "http://ho%5Bst/",
4847+
"base": "about:blank",
4848+
"failure": true
4849+
},
4850+
{
4851+
"input": "http://ho%5Cst/",
4852+
"base": "about:blank",
4853+
"failure": true
4854+
},
4855+
{
4856+
"input": "http://ho%5Dst/",
4857+
"base": "about:blank",
4858+
"failure": true
4859+
},
4860+
{
4861+
"input": "http://ho%7Cst/",
4862+
"base": "about:blank",
4863+
"failure": true
4864+
},
47014865
"Allowed host code points",
47024866
{
47034867
"input": "http://\u001F!\"$&'()*+,-.;=_`{}~/",
@@ -7676,7 +7840,8 @@
76767840
"search": "",
76777841
"username": "joe"
76787842
},
7679-
{ "input": "foo://!\"$%&'()*+,-.;=_`{}~/",
7843+
{
7844+
"input": "foo://!\"$%&'()*+,-.;=_`{}~/",
76807845
"base": "about:blank",
76817846
"hash": "",
76827847
"host": "!\"$%&'()*+,-.;=_`{}~",
@@ -7794,5 +7959,62 @@
77947959
"protocol": "wss:",
77957960
"search": "",
77967961
"username": ""
7962+
},
7963+
"Ensure that input schemes are not ignored when resolving non-special URLs",
7964+
{
7965+
"input": "abc:rootless",
7966+
"base": "abc://host/path",
7967+
"hash": "",
7968+
"host": "",
7969+
"hostname": "",
7970+
"href":"abc:rootless",
7971+
"password": "",
7972+
"pathname": "rootless",
7973+
"port":"",
7974+
"protocol": "abc:",
7975+
"search": "",
7976+
"username": ""
7977+
},
7978+
{
7979+
"input": "abc:rootless",
7980+
"base": "abc:/path",
7981+
"hash": "",
7982+
"host": "",
7983+
"hostname": "",
7984+
"href":"abc:rootless",
7985+
"password": "",
7986+
"pathname": "rootless",
7987+
"port":"",
7988+
"protocol": "abc:",
7989+
"search": "",
7990+
"username": ""
7991+
},
7992+
{
7993+
"input": "abc:rootless",
7994+
"base": "abc:path",
7995+
"hash": "",
7996+
"host": "",
7997+
"hostname": "",
7998+
"href":"abc:rootless",
7999+
"password": "",
8000+
"pathname": "rootless",
8001+
"port":"",
8002+
"protocol": "abc:",
8003+
"search": "",
8004+
"username": ""
8005+
},
8006+
{
8007+
"input": "abc:/rooted",
8008+
"base": "abc://host/path",
8009+
"hash": "",
8010+
"host": "",
8011+
"hostname": "",
8012+
"href":"abc:/rooted",
8013+
"password": "",
8014+
"pathname": "/rooted",
8015+
"port":"",
8016+
"protocol": "abc:",
8017+
"search": "",
8018+
"username": ""
77978019
}
77988020
]

test/fixtures/wpt/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"path": "resources"
4545
},
4646
"url": {
47-
"commit": "1fcb39223d3009fbb46c1b254755d6cc75e290f1",
47+
"commit": "41590413afa23bd29e452287b816423014e84cd7",
4848
"path": "url"
4949
}
5050
}

0 commit comments

Comments
 (0)