url: fix file url reparse
Fixes: https://github.com/nodejs/node/issues/35571 Refs: https://github.com/whatwg/url/pull/550 Refs: https://github.com/web-platform-tests/wpt/pull/25989 PR-URL: https://github.com/nodejs/node/pull/35671 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This commit is contained in:
parent
c55f661551
commit
7afe3af200
@ -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];
|
||||
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
@ -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) {
|
||||
@ -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) {
|
||||
@ -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) {
|
||||
@ -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) {
|
||||
|
2
test/fixtures/wpt/README.md
vendored
2
test/fixtures/wpt/README.md
vendored
@ -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
|
||||
|
31
test/fixtures/wpt/url/resources/urltestdata.json
vendored
31
test/fixtures/wpt/url/resources/urltestdata.json
vendored
@ -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",
|
||||
@ -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::]",
|
||||
|
2
test/fixtures/wpt/versions.json
vendored
2
test/fixtures/wpt/versions.json
vendored
@ -8,7 +8,7 @@
|
||||
"path": "encoding"
|
||||
},
|
||||
"url": {
|
||||
"commit": "4e15edcc3ca51c72c3846133c7b175ecd94b3a9b",
|
||||
"commit": "33e4ac09029c463ea6ee57d6f33477a9043e98e8",
|
||||
"path": "url"
|
||||
},
|
||||
"resources": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user