Skip to content

Commit

Permalink
Merge pull request #751 from crowlKats/whatwg/url#589
Browse files Browse the repository at this point in the history
Forbid | in URL hosts
  • Loading branch information
valenting authored Jan 31, 2022
2 parents fc76310 + 3dc30d1 commit 38c8e9d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 18 deletions.
34 changes: 16 additions & 18 deletions url/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,21 @@ impl Host<String> {
}

let is_invalid_domain_char = |c| {
matches!(
c,
| '\0'..='\u{001F}'
| ' '
| '#'
| '%'
| '/'
| ':'
| '<'
| '>'
| '?'
| '@'
| '['
| '\\'
| ']'
| '^'
| '\u{007F}'
)
matches!(c, |'\0'..='\u{001F}'| ' '
| '#'
| '%'
| '/'
| ':'
| '<'
| '>'
| '?'
| '@'
| '['
| '\\'
| ']'
| '^'
| '\u{007F}'
| '|')
};

if domain.find(is_invalid_domain_char).is_some() {
Expand Down Expand Up @@ -146,6 +143,7 @@ impl Host<String> {
| '\\'
| ']'
| '^'
| '|'
)
};

Expand Down
45 changes: 45 additions & 0 deletions url/tests/urltestdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4707,6 +4707,11 @@
"base": "about:blank",
"failure": true
},
{
"input": "sc://a|b/",
"base": "about:blank",
"failure": true
},
"Forbidden host codepoints: tabs and newlines are removed during preprocessing",
{
"input": "foo://ho\u0009st/",
Expand Down Expand Up @@ -4931,6 +4936,11 @@
"base": "about:blank",
"failure": true
},
{
"input": "http://a|b/",
"base": "about:blank",
"failure": true
},
{
"input": "http://a\u007Fb/",
"base": "about:blank",
Expand Down Expand Up @@ -5200,6 +5210,11 @@
"base": "about:blank",
"failure": true
},
{
"input": "http://ho%7Cst/",
"base": "about:blank",
"failure": true
},
{
"input": "http://ho%7Fst/",
"base": "about:blank",
Expand Down Expand Up @@ -5777,6 +5792,36 @@
"base": "about:blank",
"failure": true
},
{
"input": "file://%43%7C",
"base": "about:blank",
"failure": true
},
{
"input": "file://%43|",
"base": "about:blank",
"failure": true
},
{
"input": "file://C%7C",
"base": "about:blank",
"failure": true
},
{
"input": "file://%43%7C/",
"base": "about:blank",
"failure": true
},
{
"input": "https://%43%7C/",
"base": "about:blank",
"failure": true
},
{
"input": "asdf://%43|/",
"base": "about:blank",
"failure": true
},
{
"input": "asdf://%43%7C/",
"base": "about:blank",
Expand Down

0 comments on commit 38c8e9d

Please sign in to comment.