Skip to content

Commit

Permalink
URL: test the host parser
Browse files Browse the repository at this point in the history
See whatwg/url#159 for context.
  • Loading branch information
annevk committed Jan 4, 2017
1 parent 1e1e804 commit 15aa999
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions url/host-parser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!doctype html>
<title>Testing the host parser</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<script>
for(let i = 0; i < 0x7F; i++) {
let str = String.fromCharCode(i)
let shouldPass = true
let onlySetters = false
if(str.match(/[a-z0-9]/i)) {
// Skip things we know will work
continue
}
if(str.match(/\x09|\x0A|\x0D|\?|\/|\\|:|@|#/)) {
shouldPass = false
onlySetters = true
}
if(str.match(/\x00|\x20|%|\[|\]/)) {
shouldPass = false
}

if(!onlySetters) {
test(() => {
if(shouldPass) {
const url = new URL("https://" + str + "x")
assert_equals(url.pathname, "/")
assert_equals(url.host, str + "x")
assert_equals(url.hostname, str + "x")
} else {
assert_throws(new TypeError, () => new URL("https://" + str + "x"))
}
}, encodeURI(str))
}

test(() => {
const url = new URL("https://x")
;["host", "hostname"].forEach((val) => {
url[val] = str
if(shouldPass) {
assert_equals(url[val], str)
} else {
assert_equals(url[val], "x")
}
})
}, "host/hostname setter for " + encodeURI(str))
}
</script>

0 comments on commit 15aa999

Please sign in to comment.