Debian Codegraph @

rhino/testsrc/jstests/660799.jstest

raw
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 function assertThrows(s) {
6 try {
7 decodeURI(s);
8 } catch (e) {
9 if (!(e instanceof URIError)) {
10 throw "decodeURI('" + s + "') threw " + e + " instead of URIError";
11 }
12 return;
13 }
14 throw "Excpected decodeURI('" + s + "') to throw URIError.";
15 }
16
17 function assertEquals(a, b) {
18 if (decodeURI(a) !== b)
19 throw "Expected decodeURI('" + a + "') to be equal to " + b;
20 }
21
22 //Phase1: overlong sequences
23 assertThrows("%C1%BF");
24 assertThrows("%E0%9F%BF");
25 assertThrows("%F0%88%80%80");
26 assertThrows("%F0%8F%BF%BF");
27 assertThrows("%F0%80%C0%80%80");
28 assertThrows("%F8%84%8F%BF%BF");
29 assertThrows("%FC%80%84%8F%BF%BF");
30
31 assertThrows("%C1%BF");
32 assertThrows("%E0%9F%BF");
33
34 //Phase 2:Out of Unicode range
35
36 assertThrows("%F4%90%80%80%80");
37 assertThrows("%F8%84%90%80%80");
38 assertThrows("%FC%80%84%90%80%80");
39
40 assertThrows("%ED%A0%80");
41 assertThrows("%ED%AF%BF");
42 assertThrows("%ED%B0%80");
43 assertThrows("%ED%BF%BF");
44
45
46 //Phase 3:Valid sequences must be decoded correctly
47
48 assertEquals("%7F", "\x7f");
49 assertEquals("%C2%80", "\x80");
50 assertEquals("%E0%A0%80", "\u0800");
51 assertEquals("%F0%90%80%80", "\uD800\uDC00");
52 assertEquals("%F4%8F%BF%BF", "\uDBFF\uDFFF");
53
54 "success"