diff --git a/lib/internal/url.js b/lib/internal/url.js index 3c464ffbd638f6..b82c36db92e0bb 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -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)); } diff --git a/src/node_url.cc b/src/node_url.cc index 466f3c689a51f8..226fa69693558e 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -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) { diff --git a/test/fixtures/wpt/README.md b/test/fixtures/wpt/README.md index 5428e4c183abfc..1ae38fa52d8e90 100644 --- a/test/fixtures/wpt/README.md +++ b/test/fixtures/wpt/README.md @@ -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 diff --git a/test/fixtures/wpt/url/resources/urltestdata.json b/test/fixtures/wpt/url/resources/urltestdata.json index c7a906c82e5acc..f55a40338a30dd 100644 --- a/test/fixtures/wpt/url/resources/urltestdata.json +++ b/test/fixtures/wpt/url/resources/urltestdata.json @@ -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::]", diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index 014d1f00078a19..74d7d39a10360a 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -8,7 +8,7 @@ "path": "encoding" }, "url": { - "commit": "4e15edcc3ca51c72c3846133c7b175ecd94b3a9b", + "commit": "33e4ac09029c463ea6ee57d6f33477a9043e98e8", "path": "url" }, "resources": {