Skip to content

Commit b8d1a45

Browse files
watildeevanlucas
authored andcommitted
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. PR-URL: #12507 Fixes: #11962 Refs: whatwg/url#213 Reviewed-By: James M Snell <[email protected]>
1 parent 078316c commit b8d1a45

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/node_url.cc

+23-5
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,10 @@ namespace url {
862862
}
863863
break;
864864
case kRelativeSlash:
865-
if (ch == '/' || special_back_slash) {
865+
if (IsSpecial(url->scheme) && (ch == '/' || ch == '\\')) {
866866
state = kSpecialAuthorityIgnoreSlashes;
867+
} else if (ch == '/') {
868+
state = kAuthority;
867869
} else {
868870
if (base->flags & URL_FLAGS_HAS_USERNAME) {
869871
url->flags |= URL_FLAGS_HAS_USERNAME;
@@ -1145,9 +1147,25 @@ namespace url {
11451147
}
11461148
break;
11471149
case kPathStart:
1148-
state = kPath;
1149-
if (ch != '/' && !special_back_slash)
1150-
continue;
1150+
if (IsSpecial(url->scheme)) {
1151+
state = kPath;
1152+
if (ch != '/' && ch != '\\') {
1153+
continue;
1154+
}
1155+
} else if (!has_state_override && ch == '?') {
1156+
url->flags |= URL_FLAGS_HAS_QUERY;
1157+
url->query.clear();
1158+
state = kQuery;
1159+
} else if (!has_state_override && ch == '#') {
1160+
url->flags |= URL_FLAGS_HAS_FRAGMENT;
1161+
url->fragment.clear();
1162+
state = kFragment;
1163+
} else if (ch != kEOL) {
1164+
state = kPath;
1165+
if (ch != '/') {
1166+
continue;
1167+
}
1168+
}
11511169
break;
11521170
case kPath:
11531171
if (ch == kEOL ||
@@ -1165,7 +1183,7 @@ namespace url {
11651183
url->flags |= URL_FLAGS_HAS_PATH;
11661184
url->path.push_back("");
11671185
}
1168-
} else {
1186+
} else if (!IsSingleDotSegment(buffer)) {
11691187
if (url->scheme == "file:" &&
11701188
url->path.empty() &&
11711189
buffer.size() == 2 &&

0 commit comments

Comments
 (0)