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