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: change path parsing for non-special URLs #12058

Closed
wants to merge 3 commits 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
28 changes: 23 additions & 5 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,10 @@ namespace url {
}
break;
case kRelativeSlash:
if (ch == '/' || special_back_slash) {
if (IsSpecial(url->scheme) && (ch == '/' || ch == '\\')) {
state = kSpecialAuthorityIgnoreSlashes;
} else if (ch == '/') {
state = kAuthority;
} else {
if (base->flags & URL_FLAGS_HAS_USERNAME) {
url->flags |= URL_FLAGS_HAS_USERNAME;
Expand Down Expand Up @@ -1145,9 +1147,25 @@ namespace url {
}
break;
case kPathStart:
state = kPath;
if (ch != '/' && !special_back_slash)
continue;
if (IsSpecial(url->scheme)) {
state = kPath;
if (ch != '/' && ch != '\\') {
continue;
}
} else if (!has_state_override && ch == '?') {
url->flags |= URL_FLAGS_HAS_QUERY;
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for not being clear. Keep the url->query.clear() there, in addition to setting the flag.

Copy link
Member Author

Choose a reason for hiding this comment

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

oops, I misunderstood it sorry! updated.

url->query.clear();
state = kQuery;
} else if (!has_state_override && ch == '#') {
url->flags |= URL_FLAGS_HAS_FRAGMENT;
url->fragment.clear();
state = kFragment;
} else if (ch != kEOL) {
state = kPath;
if (ch != '/') {
continue;
}
}
break;
case kPath:
if (ch == kEOL ||
Expand All @@ -1165,7 +1183,7 @@ namespace url {
url->flags |= URL_FLAGS_HAS_PATH;
url->path.push_back("");
}
} else {
} else if (!IsSingleDotSegment(buffer)) {
if (url->scheme == "file:" &&
url->path.empty() &&
buffer.size() == 2 &&
Expand Down
Loading