diff options
author | Daijiro Wachi <daijiro.wachi@gmail.com> | 2020-10-05 13:22:44 +0300 |
---|---|---|
committer | Daijiro Wachi <daijiro.wachi@gmail.com> | 2020-10-12 09:06:55 +0300 |
commit | bb62f4ad9e10007734c737c85df718eafa626503 (patch) | |
tree | 0cab6c8c778aa2cfc317140bbcbf8afbe2b4f524 /src/node_url.cc | |
parent | a844387eaaa726ecc33adaa24d35ca980b65f2aa (diff) |
url: file URL path normalization
Refs: https://github.com/whatwg/url/pull/544
Refs: https://github.com/web-platform-tests/wpt/pull/25716
PR-URL: https://github.com/nodejs/node/pull/35477
Fixes: https://github.com/nodejs/node/issues/35429
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'src/node_url.cc')
-rw-r--r-- | src/node_url.cc | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/src/node_url.cc b/src/node_url.cc index b7aeb8b0062..466f3c689a5 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -1904,16 +1904,19 @@ void URL::Parse(const char* input, state = kFragment; break; 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) { + url->flags |= URL_FLAGS_HAS_PATH; + url->path = base->path; + } if (!StartsWithWindowsDriveLetter(p, end)) { - if (base->flags & URL_FLAGS_HAS_HOST) { - url->flags |= URL_FLAGS_HAS_HOST; - url->host = base->host; - } - if (base->flags & URL_FLAGS_HAS_PATH) { - url->flags |= URL_FLAGS_HAS_PATH; - url->path = base->path; - } ShortenUrlPath(url); + } else { + url->path.clear(); } state = kPath; continue; @@ -1927,20 +1930,13 @@ void URL::Parse(const char* input, if (ch == '/' || ch == '\\') { state = kFileHost; } else { - if (has_base && - base->scheme == "file:" && - !StartsWithWindowsDriveLetter(p, end)) { - if (IsNormalizedWindowsDriveLetter(base->path[0])) { + if (has_base && base->scheme == "file:") { + url->flags |= URL_FLAGS_HAS_HOST; + url->host = base->host; + if (!StartsWithWindowsDriveLetter(p, end) && + IsNormalizedWindowsDriveLetter(base->path[0])) { url->flags |= URL_FLAGS_HAS_PATH; url->path.push_back(base->path[0]); - } else { - if (base->flags & URL_FLAGS_HAS_HOST) { - url->flags |= URL_FLAGS_HAS_HOST; - url->host = base->host; - } else { - url->flags &= ~URL_FLAGS_HAS_HOST; - url->host.clear(); - } } } state = kPath; @@ -2024,29 +2020,19 @@ void URL::Parse(const char* input, url->path.empty() && buffer.size() == 2 && IsWindowsDriveLetter(buffer)) { - if ((url->flags & URL_FLAGS_HAS_HOST) && - !url->host.empty()) { - url->host.clear(); - url->flags |= URL_FLAGS_HAS_HOST; - } buffer[1] = ':'; } url->flags |= URL_FLAGS_HAS_PATH; url->path.emplace_back(std::move(buffer)); } buffer.clear(); - if (url->scheme == "file:" && - (ch == kEOL || - ch == '?' || - ch == '#')) { - while (url->path.size() > 1 && url->path[0].empty()) { - url->path.erase(url->path.begin()); - } - } if (ch == '?') { url->flags |= URL_FLAGS_HAS_QUERY; + url->query.clear(); state = kQuery; } else if (ch == '#') { + url->flags |= URL_FLAGS_HAS_FRAGMENT; + url->fragment.clear(); state = kFragment; } } else { |