Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_bug412457.js
blobca545115b0b94f03df677e7a7230143981ae4583
1 "use strict";
3 function run_test() {
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");
8 // escaped UTF8
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.
15 Assert.throws(
16 () => {
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
42 Assert.throws(
43 () => {
44 newURI = newURI.mutate().setSpec("http://example.com%3ffoo").finalize();
46 /NS_ERROR_MALFORMED_URI/,
47 "bad escaped character"
49 Assert.throws(
50 () => {
51 newURI = newURI.mutate().setSpec("http://example.com%23foo").finalize();
53 /NS_ERROR_MALFORMED_URI/,
54 "bad escaped character"
56 Assert.throws(
57 () => {
58 newURI = newURI.mutate().setSpec("http://example.com%3a80").finalize();
60 /NS_ERROR_MALFORMED_URI/,
61 "bad escaped character"
63 Assert.throws(
64 () => {
65 newURI = newURI.mutate().setSpec("http://example.com%2ffoo").finalize();
67 /NS_ERROR_MALFORMED_URI/,
68 "bad escaped character"
70 Assert.throws(
71 () => {
72 newURI = newURI.mutate().setSpec("http://example.com%00").finalize();
74 /NS_ERROR_MALFORMED_URI/,
75 "bad escaped character"