Skip to content

Commit d97fd8e

Browse files
committed
url: split forbidden host/domain code points, and add all C0 controls and add U+007F to the latter
1 parent 5ad2a9b commit d97fd8e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/node_url.cc

+17-8
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ enum url_cb_args {
166166
// https://infra.spec.whatwg.org/#ascii-tab-or-newline
167167
CHAR_TEST(8, IsASCIITabOrNewline, (ch == '\t' || ch == '\n' || ch == '\r'))
168168

169+
// https://infra.spec.whatwg.org/#c0-control
170+
CHAR_TEST(8, IsC0Control, (ch >= '\0' && ch <= '\x1f'))
171+
169172
// https://infra.spec.whatwg.org/#c0-control-or-space
170173
CHAR_TEST(8, IsC0ControlOrSpace, (ch >= '\0' && ch <= ' '))
171174

@@ -191,12 +194,18 @@ T ASCIILowercase(T ch) {
191194
}
192195

193196
// https://url.spec.whatwg.org/#forbidden-host-code-point
194-
CHAR_TEST(8, IsForbiddenHostCodePoint,
195-
ch == '\0' || ch == '\t' || ch == '\n' || ch == '\r' ||
196-
ch == ' ' || ch == '#' || ch == '%' || ch == '/' ||
197-
ch == ':' || ch == '?' || ch == '@' || ch == '[' ||
198-
ch == '<' || ch == '>' || ch == '\\' || ch == ']' ||
199-
ch == '^' || ch == '|')
197+
CHAR_TEST(8,
198+
IsForbiddenHostCodePoint,
199+
ch == '\0' || ch == '\t' || ch == '\n' || ch == '\r' || ch == ' ' ||
200+
ch == '#' || ch == '/' || ch == ':' || ch == '?' || ch == '@' ||
201+
ch == '[' || ch == '<' || ch == '>' || ch == '\\' || ch == ']' ||
202+
ch == '^' || ch == '|')
203+
204+
// https://url.spec.whatwg.org/#forbidden-domain-code-point
205+
CHAR_TEST(8,
206+
IsForbiddenDomainCodePoint,
207+
IsForbiddenHostCodePoint(ch) || IsC0Control(ch) || ch == '%' ||
208+
ch == '\x7f')
200209

201210
// https://url.spec.whatwg.org/#windows-drive-letter
202211
TWO_CHAR_STRING_TEST(8, IsWindowsDriveLetter,
@@ -484,7 +493,7 @@ void URLHost::ParseOpaqueHost(const char* input, size_t length) {
484493
output.reserve(length);
485494
for (size_t i = 0; i < length; i++) {
486495
const char ch = input[i];
487-
if (ch != '%' && IsForbiddenHostCodePoint(ch)) {
496+
if (IsForbiddenHostCodePoint(ch)) {
488497
return;
489498
} else {
490499
AppendOrEscape(&output, ch, C0_CONTROL_ENCODE_SET);
@@ -523,7 +532,7 @@ void URLHost::ParseHost(const char* input,
523532
// If any of the following characters are still present, we have to fail
524533
for (size_t n = 0; n < decoded.size(); n++) {
525534
const char ch = decoded[n];
526-
if (IsForbiddenHostCodePoint(ch)) {
535+
if (IsForbiddenDomainCodePoint(ch)) {
527536
return;
528537
}
529538
}

0 commit comments

Comments
 (0)