4 // check if hostname is unescaped before applying IDNA
5 var newURI
= Services
.io
.newURI("http://\u5341%2ecom/");
6 Assert
.equal(newURI
.asciiHost
, "xn--kkr.com");
9 newURI
= newURI
.mutate().setSpec("http://%e5%8d%81.com").finalize();
10 Assert
.equal(newURI
.asciiHost
, "xn--kkr.com");
12 // There should be only allowed characters in hostname after
13 // unescaping and attempting to apply IDNA. "\x80" is illegal in
14 // UTF-8, so IDNA fails, and 0x80 is illegal in DNS too.
17 newURI
= newURI
.mutate().setSpec("http://%80.com").finalize();
19 /NS_ERROR_MALFORMED_URI/,
20 "illegal UTF character"
23 // test parsing URL with all possible host terminators
24 newURI
= newURI
.mutate().setSpec("http://example.com?foo").finalize();
25 Assert
.equal(newURI
.asciiHost
, "example.com");
27 newURI
= newURI
.mutate().setSpec("http://example.com#foo").finalize();
28 Assert
.equal(newURI
.asciiHost
, "example.com");
30 newURI
= newURI
.mutate().setSpec("http://example.com:80").finalize();
31 Assert
.equal(newURI
.asciiHost
, "example.com");
33 newURI
= newURI
.mutate().setSpec("http://example.com/foo").finalize();
34 Assert
.equal(newURI
.asciiHost
, "example.com");
36 // Test an intuitively weird character that is not actually on the
37 // forbidden domain code point list in the WHATWG URL Standard.
38 newURI
= newURI
.mutate().setSpec("http://example.com%3bfoo").finalize();
39 Assert
.equal(newURI
.asciiHost
, "example.com;foo");
41 // Characters that are invalid in the host
44 newURI
= newURI
.mutate().setSpec("http://example.com%3ffoo").finalize();
46 /NS_ERROR_MALFORMED_URI/,
47 "bad escaped character"
51 newURI
= newURI
.mutate().setSpec("http://example.com%23foo").finalize();
53 /NS_ERROR_MALFORMED_URI/,
54 "bad escaped character"
58 newURI
= newURI
.mutate().setSpec("http://example.com%3a80").finalize();
60 /NS_ERROR_MALFORMED_URI/,
61 "bad escaped character"
65 newURI
= newURI
.mutate().setSpec("http://example.com%2ffoo").finalize();
67 /NS_ERROR_MALFORMED_URI/,
68 "bad escaped character"
72 newURI
= newURI
.mutate().setSpec("http://example.com%00").finalize();
74 /NS_ERROR_MALFORMED_URI/,
75 "bad escaped character"