Skip to content

Commit

Permalink
Fix host_parser::parse_host function
Browse files Browse the repository at this point in the history
Do not report error on forbidden < and > characters if they are NFC
normalized to valid ones.
  • Loading branch information
rmisev committed Jun 23, 2024
1 parent 98b7d8d commit 7e84519
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
10 changes: 7 additions & 3 deletions include/upa/url_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,13 @@ inline validation_errc host_parser::parse_host(const CharT* first, const CharT*
return validation_errc::ok;
}
} else if (static_cast<UCharT>(*ptr) < 0x80 && *ptr != '%') {
// 7. If asciiDomain contains a forbidden domain code point, domain-invalid-code-point
// validation error, return failure.
return validation_errc::domain_invalid_code_point;
// NFC normalizes U+003C (<), U+003D (=), U+003E (>) characters if they precede
// U+0338. Therefore, no errors are reported here for forbidden < and > characters
// if there is a possibility to normalize them.
if (!(*ptr >= 0x3C && *ptr <= 0x3E && ptr + 1 < last && static_cast<UCharT>(ptr[1]) >= 0x80))
// 7. If asciiDomain contains a forbidden domain code point, domain-invalid-code-point
// validation error, return failure.
return validation_errc::domain_invalid_code_point;
}

// Input for domain_to_ascii
Expand Down
28 changes: 28 additions & 0 deletions test/data/my-toascii.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"comment": "NFC normalization (forbidden < and > characters are normalized to valid ones)",
"input": "=\u0338",
"output": "xn--1ch"
},
{
"input": "<\u0338",
"output": "xn--gdh"
},
{
"input": ">\u0338",
"output": "xn--hdh"
},
{
"comment": "Same with inserted IDNA ignored code point",
"input": "=\u00AD\u0338",
"output": "xn--1ch"
},
{
"input": "<\u00AD\u0338",
"output": "xn--gdh"
},
{
"input": ">\u00AD\u0338",
"output": "xn--hdh"
}
]
1 change: 1 addition & 0 deletions test/wpt-url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ int main(int argc, char** argv)

// additional tests
err |= test_from_file(run_parser_tests, "data/my-urltestdata.json");
err |= test_from_file(run_host_parser_tests, "data/my-toascii.json");
err |= test_from_file(run_setter_tests, "data/my-setters_tests.json");

// Free memory
Expand Down

0 comments on commit 7e84519

Please sign in to comment.