blob: 72636a46919214d326db229f21f81da32b74127d [file] [log] [blame]
ap@apple.com12626442015-02-11 18:03:42 +00001<!DOCTYPE html>
2<html>
3<head>
4<meta charset="utf-8">
5<script src="../../resources/js-test.js"></script>
6</head>
7<body>
8<script>
9
10description("Test that URL username and password accessors encode/decode correctly");
11
12function build(username, password)
13{
14 var url = new URL("http://www.apple.com");
15 if (username)
16 url.username = username;
17 if (password)
18 url.password = password;
19 return url;
20}
21
22debug("\nBasic syntax");
23
24shouldBe("build('user').toString()", '"http://user@www.apple.com/"');
25shouldBe("build('user').username", '"user"');
26
27shouldBe("build('%').toString()", '"http://%@www.apple.com/"');
28shouldBe("build('%').username", '"%"');
29
30shouldBe("build('%%').toString()", '"http://%%@www.apple.com/"');
31shouldBe("build('%%').username", '"%%"');
32
33shouldBe("build('%z').toString()", '"http://%z@www.apple.com/"');
34shouldBe("build('%z').username", '"%z"');
35
36// Yes, this is weird, percent signs don't get encoded.
37shouldBe("build('%61').toString()", '"http://%61@www.apple.com/"');
38shouldBe("build('%61').username", '"%61"');
39shouldBe("build('%40').toString()", '"http://%40@www.apple.com/"');
40shouldBe("build('%40').username", '"%40"');
41
42debug("\nSimple encode set");
43shouldBe("build('\x07\x7f').toString()", '"http://%07%7F@www.apple.com/"');
44shouldBe("build('user', '\x07\x7f').toString()", '"http://user:%07%7F@www.apple.com/"');
45
46debug("\nDefault encode set additions");
47shouldBe("build(' \"#><?`').toString()", '"http://%20%22%23%3E%3C%3F%60@www.apple.com/"');
48shouldBe("build('user', ' \"#><?`').toString()", '"http://user:%20%22%23%3E%3C%3F%60@www.apple.com/"');
49
50debug("\nPassword encode set additions");
51shouldBe("build('/@\\\\').toString()", '"http://%2F%40%5C@www.apple.com/"');
52shouldBe("build('user', '/@\\\\').toString()", '"http://user:%2F%40%5C@www.apple.com/"');
53debug("':' shouldn't be encoded in the password per the URL Standard, although both Firefox and Chrome encode it")
54shouldBe("build('user', ':').toString()", '"http://user::@www.apple.com/"');
55
56debug("\nUsername encode set addition");
57shouldBe("build(':').toString()", '"http://%3A@www.apple.com/"');
58
59debug("\n8-bit");
60shouldBe("build('юзер', 'пароль').toString()", '"http://%D1%8E%D0%B7%D0%B5%D1%80:%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%8C@www.apple.com/"');
61shouldBe("build('юзер').username", '"%D1%8E%D0%B7%D0%B5%D1%80"');
62shouldBe("build('user', 'пароль').password", '"%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%8C"');
63
64debug("\nSome special characters that don't get encoded when used in credentials");
65shouldBe("build('!$&*()-+~').toString()", '"http://!$&*()-+~@www.apple.com/"');
66
67debug("\nSome characters that shouldn't be encoded per the URL Standard, although both Firefox and Chrome encode them")
68shouldBe("build('^{|}[]=').toString()", '"http://^{|}[]=@www.apple.com/"');
69
70</script>
71</body>
72</html>