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 // Characters that are invalid in the host
39 newURI = newURI.mutate().setSpec("http://example.com%3ffoo").finalize();
41 /NS_ERROR_MALFORMED_URI/,
42 "bad escaped character"
46 newURI = newURI.mutate().setSpec("http://example.com%23foo").finalize();
48 /NS_ERROR_MALFORMED_URI/,
49 "bad escaped character"
53 newURI = newURI.mutate().setSpec("http://example.com%3bfoo").finalize();
55 /NS_ERROR_MALFORMED_URI/,
56 "bad escaped character"
60 newURI = newURI.mutate().setSpec("http://example.com%3a80").finalize();
62 /NS_ERROR_MALFORMED_URI/,
63 "bad escaped character"
67 newURI = newURI.mutate().setSpec("http://example.com%2ffoo").finalize();
69 /NS_ERROR_MALFORMED_URI/,
70 "bad escaped character"
74 newURI = newURI.mutate().setSpec("http://example.com%00").finalize();
76 /NS_ERROR_MALFORMED_URI/,
77 "bad escaped character"