Skip to content

Commit 943dd5f

Browse files
watildeTimothyGu
authored andcommitted
url: handle windows drive letter in the file state
`C|` should not satisfy the condition to not copy the base's path. It also synchronises WPT url test data to verify the update in upstream. PR-URL: #12808 Refs: whatwg/url#305 Refs: web-platform-tests/wpt#5754 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Timothy Gu <[email protected]>
1 parent 0258aed commit 943dd5f

File tree

2 files changed

+105
-4
lines changed

2 files changed

+105
-4
lines changed

src/node_url.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,7 @@ void URL::Parse(const char* input,
11691169

11701170
while (p <= end) {
11711171
const char ch = p < end ? p[0] : kEOL;
1172+
const size_t remaining = end == p ? 0 : (end - p - 1);
11721173

11731174
if (IsASCIITabOrNewline(ch)) {
11741175
if (state == kAuthority) {
@@ -1653,9 +1654,10 @@ void URL::Parse(const char* input,
16531654
state = kFragment;
16541655
break;
16551656
default:
1656-
if ((!IsWindowsDriveLetter(ch, p[1]) ||
1657-
end - p == 1 ||
1658-
(p[2] != '/' &&
1657+
if ((remaining == 0 ||
1658+
!IsWindowsDriveLetter(ch, p[1]) ||
1659+
(remaining >= 2 &&
1660+
p[2] != '/' &&
16591661
p[2] != '\\' &&
16601662
p[2] != '?' &&
16611663
p[2] != '#'))) {

test/fixtures/url-tests.js

+100-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
/* WPT Refs:
4-
https://github.com/w3c/web-platform-tests/blob/3afae94/url/urltestdata.json
4+
https://github.com/w3c/web-platform-tests/blob/28541bb/url/urltestdata.json
55
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
66
*/
77
module.exports =
@@ -5430,6 +5430,105 @@ module.exports =
54305430
"search": "?chai",
54315431
"hash": ""
54325432
},
5433+
"# Windows drive letter handling with the 'file:' base URL",
5434+
{
5435+
"input": "C|",
5436+
"base": "file://host/dir/file",
5437+
"href": "file:///C:",
5438+
"protocol": "file:",
5439+
"username": "",
5440+
"password": "",
5441+
"host": "",
5442+
"hostname": "",
5443+
"port": "",
5444+
"pathname": "/C:",
5445+
"search": "",
5446+
"hash": ""
5447+
},
5448+
{
5449+
"input": "C|#",
5450+
"base": "file://host/dir/file",
5451+
"href": "file:///C:#",
5452+
"protocol": "file:",
5453+
"username": "",
5454+
"password": "",
5455+
"host": "",
5456+
"hostname": "",
5457+
"port": "",
5458+
"pathname": "/C:",
5459+
"search": "",
5460+
"hash": ""
5461+
},
5462+
{
5463+
"input": "C|?",
5464+
"base": "file://host/dir/file",
5465+
"href": "file:///C:?",
5466+
"protocol": "file:",
5467+
"username": "",
5468+
"password": "",
5469+
"host": "",
5470+
"hostname": "",
5471+
"port": "",
5472+
"pathname": "/C:",
5473+
"search": "",
5474+
"hash": ""
5475+
},
5476+
{
5477+
"input": "C|/",
5478+
"base": "file://host/dir/file",
5479+
"href": "file:///C:/",
5480+
"protocol": "file:",
5481+
"username": "",
5482+
"password": "",
5483+
"host": "",
5484+
"hostname": "",
5485+
"port": "",
5486+
"pathname": "/C:/",
5487+
"search": "",
5488+
"hash": ""
5489+
},
5490+
{
5491+
"input": "C|\\",
5492+
"base": "file://host/dir/file",
5493+
"href": "file:///C:/",
5494+
"protocol": "file:",
5495+
"username": "",
5496+
"password": "",
5497+
"host": "",
5498+
"hostname": "",
5499+
"port": "",
5500+
"pathname": "/C:/",
5501+
"search": "",
5502+
"hash": ""
5503+
},
5504+
{
5505+
"input": "C",
5506+
"base": "file://host/dir/file",
5507+
"href": "file://host/dir/C",
5508+
"protocol": "file:",
5509+
"username": "",
5510+
"password": "",
5511+
"host": "host",
5512+
"hostname": "host",
5513+
"port": "",
5514+
"pathname": "/dir/C",
5515+
"search": "",
5516+
"hash": ""
5517+
},
5518+
{
5519+
"input": "C|a",
5520+
"base": "file://host/dir/file",
5521+
"href": "file://host/dir/C|a",
5522+
"protocol": "file:",
5523+
"username": "",
5524+
"password": "",
5525+
"host": "host",
5526+
"hostname": "host",
5527+
"port": "",
5528+
"pathname": "/dir/C|a",
5529+
"search": "",
5530+
"hash": ""
5531+
},
54335532
"# Windows drive letter quirk with not empty host",
54345533
{
54355534
"input": "file://example.net/C:/",

0 commit comments

Comments
 (0)