1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
"use strict";
function run_test() {
// check if hostname is unescaped before applying IDNA
var newURI = Services.io.newURI("http://\u5341%2ecom/");
Assert.equal(newURI.asciiHost, "xn--kkr.com");
// escaped UTF8
newURI = newURI
.mutate()
.setSpec("http://%e5%8d%81.com")
.finalize();
Assert.equal(newURI.asciiHost, "xn--kkr.com");
// There should be only allowed characters in hostname after
// unescaping and attempting to apply IDNA. "\x80" is illegal in
// UTF-8, so IDNA fails, and 0x80 is illegal in DNS too.
Assert.throws(
() => {
newURI = newURI
.mutate()
.setSpec("http://%80.com")
.finalize();
},
/NS_ERROR_MALFORMED_URI/,
"illegal UTF character"
);
// test parsing URL with all possible host terminators
newURI = newURI
.mutate()
.setSpec("http://example.com?foo")
.finalize();
Assert.equal(newURI.asciiHost, "example.com");
newURI = newURI
.mutate()
.setSpec("http://example.com#foo")
.finalize();
Assert.equal(newURI.asciiHost, "example.com");
newURI = newURI
.mutate()
.setSpec("http://example.com:80")
.finalize();
Assert.equal(newURI.asciiHost, "example.com");
newURI = newURI
.mutate()
.setSpec("http://example.com/foo")
.finalize();
Assert.equal(newURI.asciiHost, "example.com");
// Characters that are invalid in the host
Assert.throws(
() => {
newURI = newURI
.mutate()
.setSpec("http://example.com%3ffoo")
.finalize();
},
/NS_ERROR_MALFORMED_URI/,
"bad escaped character"
);
Assert.throws(
() => {
newURI = newURI
.mutate()
.setSpec("http://example.com%23foo")
.finalize();
},
/NS_ERROR_MALFORMED_URI/,
"bad escaped character"
);
Assert.throws(
() => {
newURI = newURI
.mutate()
.setSpec("http://example.com%3bfoo")
.finalize();
},
/NS_ERROR_MALFORMED_URI/,
"bad escaped character"
);
Assert.throws(
() => {
newURI = newURI
.mutate()
.setSpec("http://example.com%3a80")
.finalize();
},
/NS_ERROR_MALFORMED_URI/,
"bad escaped character"
);
Assert.throws(
() => {
newURI = newURI
.mutate()
.setSpec("http://example.com%2ffoo")
.finalize();
},
/NS_ERROR_MALFORMED_URI/,
"bad escaped character"
);
Assert.throws(
() => {
newURI = newURI
.mutate()
.setSpec("http://example.com%00")
.finalize();
},
/NS_ERROR_MALFORMED_URI/,
"bad escaped character"
);
}
|