Skip to content

Commit

Permalink
URL: host parsing of URLs with unknown schemes
Browse files Browse the repository at this point in the history
URL Standard change: whatwg/url#185.
  • Loading branch information
annevk authored Jan 24, 2017
1 parent 1163fb4 commit 69c16f6
Show file tree
Hide file tree
Showing 2 changed files with 261 additions and 6 deletions.
168 changes: 166 additions & 2 deletions url/setters_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,88 @@
}
],
"host": [
{
"comment": "Non-special scheme",
"href": "sc://x/",
"new_value": "\u0000",
"expected": {
"href": "sc://x/",
"host": "x",
"hostname": "x"
}
},
{
"href": "sc://x/",
"new_value": "\u0009",
"expected": {
"href": "sc:///",
"host": "",
"hostname": ""
}
},
{
"href": "sc://x/",
"new_value": "\u000A",
"expected": {
"href": "sc:///",
"host": "",
"hostname": ""
}
},
{
"href": "sc://x/",
"new_value": "\u000D",
"expected": {
"href": "sc:///",
"host": "",
"hostname": ""
}
},
{
"href": "sc://x/",
"new_value": " ",
"expected": {
"href": "sc://x/",
"host": "x",
"hostname": "x"
}
},
{
"href": "sc://x/",
"new_value": "#",
"expected": {
"href": "sc:///",
"host": "",
"hostname": ""
}
},
{
"href": "sc://x/",
"new_value": "/",
"expected": {
"href": "sc:///",
"host": "",
"hostname": ""
}
},
{
"href": "sc://x/",
"new_value": "?",
"expected": {
"href": "sc:///",
"host": "",
"hostname": ""
}
},
{
"href": "sc://x/",
"new_value": "@",
"expected": {
"href": "sc://x/",
"host": "x",
"hostname": "x"
}
},
{
"comment": "Cannot-be-a-base means no host",
"href": "mailto:me@example.net",
Expand Down Expand Up @@ -567,7 +649,7 @@
}
},
{
"comment": "\\ is not a delimiter for non-special schemes, and it’s invalid in a domain",
"comment": "\\ is not a delimiter for non-special schemes, but still forbidden in hosts",
"href": "view-source+http://example.net/path",
"new_value": "example.com\\stuff",
"expected": {
Expand Down Expand Up @@ -680,6 +762,88 @@
}
],
"hostname": [
{
"comment": "Non-special scheme",
"href": "sc://x/",
"new_value": "\u0000",
"expected": {
"href": "sc://x/",
"host": "x",
"hostname": "x"
}
},
{
"href": "sc://x/",
"new_value": "\u0009",
"expected": {
"href": "sc:///",
"host": "",
"hostname": ""
}
},
{
"href": "sc://x/",
"new_value": "\u000A",
"expected": {
"href": "sc:///",
"host": "",
"hostname": ""
}
},
{
"href": "sc://x/",
"new_value": "\u000D",
"expected": {
"href": "sc:///",
"host": "",
"hostname": ""
}
},
{
"href": "sc://x/",
"new_value": " ",
"expected": {
"href": "sc://x/",
"host": "x",
"hostname": "x"
}
},
{
"href": "sc://x/",
"new_value": "#",
"expected": {
"href": "sc:///",
"host": "",
"hostname": ""
}
},
{
"href": "sc://x/",
"new_value": "/",
"expected": {
"href": "sc:///",
"host": "",
"hostname": ""
}
},
{
"href": "sc://x/",
"new_value": "?",
"expected": {
"href": "sc:///",
"host": "",
"hostname": ""
}
},
{
"href": "sc://x/",
"new_value": "@",
"expected": {
"href": "sc://x/",
"host": "x",
"hostname": "x"
}
},
{
"comment": "Cannot-be-a-base means no host",
"href": "mailto:me@example.net",
Expand Down Expand Up @@ -824,7 +988,7 @@
}
},
{
"comment": "\\ is not a delimiter for non-special schemes, and it’s invalid in a domain",
"comment": "\\ is not a delimiter for non-special schemes, but still forbidden in hosts",
"href": "view-source+http://example.net/path",
"new_value": "example.com\\stuff",
"expected": {
Expand Down
99 changes: 95 additions & 4 deletions url/urltestdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4256,22 +4256,102 @@
"search": "",
"hash": ""
},
"# unknown schemes and non-ASCII domains",
"# unknown schemes and their hosts",
{
"input": "sc://ñ.test/",
"base": "about:blank",
"href": "sc://xn--ida.test/",
"href": "sc://%C3%B1.test/",
"origin": "null",
"protocol": "sc:",
"username": "",
"password": "",
"host": "xn--ida.test",
"hostname": "xn--ida.test",
"host": "%C3%B1.test",
"hostname": "%C3%B1.test",
"port": "",
"pathname": "/",
"search": "",
"hash": ""
},
{
"input": "sc://\u001F!\"$&'()*+,-.;<=>^_`{|}~/",
"base": "about:blank",
"href": "sc://%1F!\"$&'()*+,-.;<=>^_`{|}~/",
"origin": "null",
"protocol": "sc:",
"username": "",
"password": "",
"host": "%1F!\"$&'()*+,-.;<=>^_`{|}~",
"hostname": "%1F!\"$&'()*+,-.;<=>^_`{|}~",
"port": "",
"pathname": "/",
"search": "",
"hash": ""
},
{
"input": "sc://\u0000/",
"base": "about:blank",
"failure": true
},
{
"input": "sc:// /",
"base": "about:blank",
"failure": true
},
{
"input": "sc://%/",
"base": "about:blank",
"failure": true
},
{
"input": "sc://@/",
"base": "about:blank",
"failure": true
},
{
"input": "sc://te@s:t@/",
"base": "about:blank",
"failure": true
},
{
"input": "sc://:/",
"base": "about:blank",
"failure": true
},
{
"input": "sc://:12/",
"base": "about:blank",
"failure": true
},
{
"input": "sc://[/",
"base": "about:blank",
"failure": true
},
{
"input": "sc://\\/",
"base": "about:blank",
"failure": true
},
{
"input": "sc://]/",
"base": "about:blank",
"failure": true
},
{
"input": "x",
"base": "sc://ñ",
"href": "sc://%C3%B1/x",
"origin": "null",
"protocol": "sc:",
"username": "",
"password": "",
"host": "%C3%B1",
"hostname": "%C3%B1",
"port": "",
"pathname": "/x",
"search": "",
"hash": ""
},
"# unknown schemes and backslashes",
{
"input": "sc:\\../",
Expand Down Expand Up @@ -4754,5 +4834,16 @@
"pathname": "/",
"search": "",
"hash": ""
},
"# Empty host",
{
"input": "http://?",
"base": "about:blank",
"failure": "true"
},
{
"input": "http://#",
"base": "about:blank",
"failure": "true"
}
]

0 comments on commit 69c16f6

Please sign in to comment.