blob: 72636a46919214d326db229f21f81da32b74127d [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../../resources/js-test.js"></script>
</head>
<body>
<script>
description("Test that URL username and password accessors encode/decode correctly");
function build(username, password)
{
var url = new URL("http://www.apple.com");
if (username)
url.username = username;
if (password)
url.password = password;
return url;
}
debug("\nBasic syntax");
shouldBe("build('user').toString()", '"http://user@www.apple.com/"');
shouldBe("build('user').username", '"user"');
shouldBe("build('%').toString()", '"http://%@www.apple.com/"');
shouldBe("build('%').username", '"%"');
shouldBe("build('%%').toString()", '"http://%%@www.apple.com/"');
shouldBe("build('%%').username", '"%%"');
shouldBe("build('%z').toString()", '"http://%z@www.apple.com/"');
shouldBe("build('%z').username", '"%z"');
// Yes, this is weird, percent signs don't get encoded.
shouldBe("build('%61').toString()", '"http://%61@www.apple.com/"');
shouldBe("build('%61').username", '"%61"');
shouldBe("build('%40').toString()", '"http://%40@www.apple.com/"');
shouldBe("build('%40').username", '"%40"');
debug("\nSimple encode set");
shouldBe("build('\x07\x7f').toString()", '"http://%07%7F@www.apple.com/"');
shouldBe("build('user', '\x07\x7f').toString()", '"http://user:%07%7F@www.apple.com/"');
debug("\nDefault encode set additions");
shouldBe("build(' \"#><?`').toString()", '"http://%20%22%23%3E%3C%3F%60@www.apple.com/"');
shouldBe("build('user', ' \"#><?`').toString()", '"http://user:%20%22%23%3E%3C%3F%60@www.apple.com/"');
debug("\nPassword encode set additions");
shouldBe("build('/@\\\\').toString()", '"http://%2F%40%5C@www.apple.com/"');
shouldBe("build('user', '/@\\\\').toString()", '"http://user:%2F%40%5C@www.apple.com/"');
debug("':' shouldn't be encoded in the password per the URL Standard, although both Firefox and Chrome encode it")
shouldBe("build('user', ':').toString()", '"http://user::@www.apple.com/"');
debug("\nUsername encode set addition");
shouldBe("build(':').toString()", '"http://%3A@www.apple.com/"');
debug("\n8-bit");
shouldBe("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/"');
shouldBe("build('юзер').username", '"%D1%8E%D0%B7%D0%B5%D1%80"');
shouldBe("build('user', 'пароль').password", '"%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%8C"');
debug("\nSome special characters that don't get encoded when used in credentials");
shouldBe("build('!$&*()-+~').toString()", '"http://!$&*()-+~@www.apple.com/"');
debug("\nSome characters that shouldn't be encoded per the URL Standard, although both Firefox and Chrome encode them")
shouldBe("build('^{|}[]=').toString()", '"http://^{|}[]=@www.apple.com/"');
</script>
</body>
</html>