url: change path parsing for non-special URLs
This changes to the way path parsing for non-special URLs. It allows paths to be empty for non-special URLs and also takes that into account when serializing. Fixes: https://github.com/nodejs/node/issues/11962 Refs: https://github.com/whatwg/url/pull/213 PR-URL: https://github.com/nodejs/node/pull/12058 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
This commit is contained in:
parent
33a19b46ca
commit
f8f46f9917
@ -862,8 +862,10 @@ namespace url {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kRelativeSlash:
|
case kRelativeSlash:
|
||||||
if (ch == '/' || special_back_slash) {
|
if (IsSpecial(url->scheme) && (ch == '/' || ch == '\\')) {
|
||||||
state = kSpecialAuthorityIgnoreSlashes;
|
state = kSpecialAuthorityIgnoreSlashes;
|
||||||
|
} else if (ch == '/') {
|
||||||
|
state = kAuthority;
|
||||||
} else {
|
} else {
|
||||||
if (base->flags & URL_FLAGS_HAS_USERNAME) {
|
if (base->flags & URL_FLAGS_HAS_USERNAME) {
|
||||||
url->flags |= URL_FLAGS_HAS_USERNAME;
|
url->flags |= URL_FLAGS_HAS_USERNAME;
|
||||||
@ -1145,9 +1147,25 @@ namespace url {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kPathStart:
|
case kPathStart:
|
||||||
state = kPath;
|
if (IsSpecial(url->scheme)) {
|
||||||
if (ch != '/' && !special_back_slash)
|
state = kPath;
|
||||||
continue;
|
if (ch != '/' && ch != '\\') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (!has_state_override && ch == '?') {
|
||||||
|
url->flags |= URL_FLAGS_HAS_QUERY;
|
||||||
|
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;
|
break;
|
||||||
case kPath:
|
case kPath:
|
||||||
if (ch == kEOL ||
|
if (ch == kEOL ||
|
||||||
@ -1165,7 +1183,7 @@ namespace url {
|
|||||||
url->flags |= URL_FLAGS_HAS_PATH;
|
url->flags |= URL_FLAGS_HAS_PATH;
|
||||||
url->path.push_back("");
|
url->path.push_back("");
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!IsSingleDotSegment(buffer)) {
|
||||||
if (url->scheme == "file:" &&
|
if (url->scheme == "file:" &&
|
||||||
url->path.empty() &&
|
url->path.empty() &&
|
||||||
buffer.size() == 2 &&
|
buffer.size() == 2 &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user