Permalink
Browse files

url: fix windows drive letter handling

Address issue with Windows drive letter handling that was
causing es-module test suite to fail.

PR-URL: #15490
Ref: whatwg/url#343
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information...
bcoe authored and BridgeAR committed Sep 21, 2017
1 parent d8a2266 commit 456d8e21eac95c291dd5e301f60d0432e6ad1b68
Showing with 389 additions and 10 deletions.
  1. +17 −8 src/node_url.cc
  2. +371 −1 test/fixtures/url-tests.js
  3. +1 −1 test/parallel/test-whatwg-url-parsing.js
View
@@ -552,6 +552,19 @@ static inline bool IsSpecial(std::string scheme) {
return false;
}
// https://url.spec.whatwg.org/#start-with-a-windows-drive-letter
static inline bool StartsWithWindowsDriveLetter(const char* p,
const char* end) {
const size_t length = end - p;
return length >= 2 &&
IsWindowsDriveLetter(p[0], p[1]) &&
(length == 2 ||
p[2] == '/' ||
p[2] == '\\' ||
p[2] == '?' ||
p[2] == '#');
}
static inline int NormalizePort(std::string scheme, int p) {
#define XX(name, port) if (scheme == name && p == port) return -1;
SPECIALS(XX);
@@ -1198,6 +1211,7 @@ void URL::Parse(const char* input,
bool special = (url->flags & URL_FLAGS_SPECIAL);
bool cannot_be_base;
const bool special_back_slash = (special && ch == '\\');
switch (state) {
case kSchemeStart:
if (IsASCIIAlpha(ch)) {
@@ -1667,13 +1681,7 @@ void URL::Parse(const char* input,
state = kFragment;
break;
default:
if ((remaining == 0 ||
!IsWindowsDriveLetter(ch, p[1]) ||
(remaining >= 2 &&
p[2] != '/' &&
p[2] != '\\' &&
p[2] != '?' &&
p[2] != '#'))) {
if (!StartsWithWindowsDriveLetter(p, end)) {
if (base->flags & URL_FLAGS_HAS_HOST) {
url->flags |= URL_FLAGS_HAS_HOST;
url->host = base->host;
@@ -1697,7 +1705,8 @@ void URL::Parse(const char* input,
state = kFileHost;
} else {
if (has_base &&
base->scheme == "file:") {
base->scheme == "file:" &&
!StartsWithWindowsDriveLetter(p, end)) {
if (IsNormalizedWindowsDriveLetter(base->path[0])) {
url->flags |= URL_FLAGS_HAS_PATH;
url->path.push_back(base->path[0]);
Oops, something went wrong.

0 comments on commit 456d8e2

Please sign in to comment.