Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: fix file url reparse #35671

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,6 @@ ObjectDefineProperties(URL.prototype, {
domainToUnicode(this.hostname) : this.hostname;
if (ctx.port !== null)
ret += `:${ctx.port}`;
} else if (ctx.scheme === 'file:') {
ret += '//';
}
if (this[cannotBeBase]) {
ret += ctx.path[0];
Expand Down Expand Up @@ -504,10 +502,6 @@ ObjectDefineProperties(URL.prototype, {
if (scheme.length === 0)
return;
const ctx = this[context];
if (ctx.scheme === 'file:' &&
(ctx.host === '' || ctx.host === null)) {
return;
}
parse(scheme, kSchemeStart, null, ctx,
onParseProtocolComplete.bind(this));
}
Expand Down
12 changes: 4 additions & 8 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1461,13 +1461,11 @@ void URL::Parse(const char* input,
((buffer == "file:") &&
((url->flags & URL_FLAGS_HAS_USERNAME) ||
(url->flags & URL_FLAGS_HAS_PASSWORD) ||
(url->port != -1)))) {
(url->port != -1))) ||
(url->scheme == "file:" && url->host.empty())) {
url->flags |= URL_FLAGS_TERMINATED;
return;
}

// File scheme && (host == empty or null) check left to JS-land
// as it can be done before even entering C++ binding.
}

url->scheme = std::move(buffer);
Expand Down Expand Up @@ -1855,13 +1853,14 @@ void URL::Parse(const char* input,
break;
case kFile:
url->scheme = "file:";
url->host.clear();
url->flags |= URL_FLAGS_HAS_HOST;
if (ch == '/' || ch == '\\') {
state = kFileSlash;
} else if (has_base && base->scheme == "file:") {
switch (ch) {
case kEOL:
if (base->flags & URL_FLAGS_HAS_HOST) {
url->flags |= URL_FLAGS_HAS_HOST;
url->host = base->host;
}
if (base->flags & URL_FLAGS_HAS_PATH) {
Expand All @@ -1875,7 +1874,6 @@ void URL::Parse(const char* input,
break;
case '?':
if (base->flags & URL_FLAGS_HAS_HOST) {
url->flags |= URL_FLAGS_HAS_HOST;
url->host = base->host;
}
if (base->flags & URL_FLAGS_HAS_PATH) {
Expand All @@ -1888,7 +1886,6 @@ void URL::Parse(const char* input,
break;
case '#':
if (base->flags & URL_FLAGS_HAS_HOST) {
url->flags |= URL_FLAGS_HAS_HOST;
url->host = base->host;
}
if (base->flags & URL_FLAGS_HAS_PATH) {
Expand All @@ -1906,7 +1903,6 @@ void URL::Parse(const char* input,
default:
url->query.clear();
if (base->flags & URL_FLAGS_HAS_HOST) {
url->flags |= URL_FLAGS_HAS_HOST;
url->host = base->host;
}
if (base->flags & URL_FLAGS_HAS_PATH) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Last update:

- console: https://github.com/web-platform-tests/wpt/tree/3b1f72e99a/console
- encoding: https://github.com/web-platform-tests/wpt/tree/d7f9e16c9a/encoding
- url: https://github.com/web-platform-tests/wpt/tree/4e15edcc3c/url
- url: https://github.com/web-platform-tests/wpt/tree/33e4ac0902/url
- resources: https://github.com/web-platform-tests/wpt/tree/1d14e821b9/resources
- interfaces: https://github.com/web-platform-tests/wpt/tree/15e47f779c/interfaces
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/2c5c3c4c27/html/webappapis/microtask-queuing
Expand Down
31 changes: 30 additions & 1 deletion test/fixtures/wpt/url/resources/urltestdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6091,7 +6091,7 @@
"base": "about:blank",
"failure": true
},
"# Additional file URL tetsts for (https://github.com/whatwg/url/issues/405)",
"# Additional file URL tests for (https://github.com/whatwg/url/issues/405)",
{
"input": "file://localhost//a//../..//foo",
"base": "about:blank",
Expand Down Expand Up @@ -6218,6 +6218,35 @@
"search": "",
"hash": ""
},
"File URL tests for https://github.com/whatwg/url/issues/549",
{
"input": "file:.//p",
"base": "about:blank",
"href": "file:////p",
"protocol": "file:",
"username": "",
"password": "",
"host": "",
"hostname": "",
"port": "",
"pathname": "//p",
"search": "",
"hash": ""
},
{
"input": "file:/.//p",
"base": "about:blank",
"href": "file:////p",
"protocol": "file:",
"username": "",
"password": "",
"host": "",
"hostname": "",
"port": "",
"pathname": "//p",
"search": "",
"hash": ""
},
"# IPv6 tests",
{
"input": "http://[1:0::]",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"path": "encoding"
},
"url": {
"commit": "4e15edcc3ca51c72c3846133c7b175ecd94b3a9b",
"commit": "33e4ac09029c463ea6ee57d6f33477a9043e98e8",
"path": "url"
},
"resources": {
Expand Down