Skip to content

Commit 382f5ce

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

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/node_url.cc

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

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

@@ -190,12 +193,18 @@ T ASCIILowercase(T ch) {
190193
}
191194

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

200209
// https://url.spec.whatwg.org/#windows-drive-letter
201210
TWO_CHAR_STRING_TEST(8, IsWindowsDriveLetter,
@@ -482,7 +491,7 @@ void URLHost::ParseOpaqueHost(const char* input, size_t length) {
482491
output.reserve(length);
483492
for (size_t i = 0; i < length; i++) {
484493
const char ch = input[i];
485-
if (ch != '%' && IsForbiddenHostCodePoint(ch)) {
494+
if (IsForbiddenHostCodePoint(ch)) {
486495
return;
487496
} else {
488497
AppendOrEscape(&output, ch, C0_CONTROL_ENCODE_SET);
@@ -521,7 +530,7 @@ void URLHost::ParseHost(const char* input,
521530
// If any of the following characters are still present, we have to fail
522531
for (size_t n = 0; n < decoded.size(); n++) {
523532
const char ch = decoded[n];
524-
if (IsForbiddenHostCodePoint(ch)) {
533+
if (IsForbiddenDomainCodePoint(ch)) {
525534
return;
526535
}
527536
}

0 commit comments

Comments
 (0)