Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: parsing should not serialize windows drive letter twice #15490

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,19 @@ static inline bool IsSpecial(std::string scheme) {
return false;
}

// https://url.spec.whatwg.org/#start-with-a-windows-drive-letter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a https://

Copy link
Contributor Author

@bcoe bcoe Sep 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm missing something:

// https://url.spec.whatwg.org/#start-with-a-windows-drive-letter

Does have https, perhaps misread?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I'm sorry. It's probably a Chrome extension I'm using.

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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand All @@ -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]);
Expand Down
Loading