diff options
author | Daijiro Wachi <daijiro.wachi@gmail.com> | 2020-10-16 07:52:16 +0300 |
---|---|---|
committer | Daijiro Wachi <daijiro.wachi@gmail.com> | 2020-10-19 09:52:45 +0300 |
commit | 7afe3af2004cc6edf8897bfcd7c568aa43d4f4e6 (patch) | |
tree | 52a7ad0bc34baf9c624f2651eeb454b25c0c21f1 /src/node_url.cc | |
parent | c55f661551d7368778ae6f9adc584467151bce8a (diff) |
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>
Diffstat (limited to 'src/node_url.cc')
-rw-r--r-- | src/node_url.cc | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/node_url.cc b/src/node_url.cc index 466f3c689a5..226fa696935 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) { |