| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="big5"> <!-- test breaks if the server overrides this --> |
| <title>Big5 encoding errors (href, han)</title> |
| <meta name="timeout" content="long"> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <script src="big5_index.js"></script> |
| <script src="big5-encoder.js"></script> |
| <link rel="author" title="Richard Ishida" href="mailto:ishida@w3.org"> |
| <link rel="help" href="https://encoding.spec.whatwg.org/#big5"> |
| <meta name="assert" content="The browser produces percent-escaped character references when writing characters to an href value and encoding han characters that are not in the gbk encoding."> |
| <script> |
| function encode(input, expected, desc) { |
| // tests whether a Unicode character is converted to an equivalent byte sequence by href |
| // input: a Unicode character |
| // expected: expected byte sequence |
| // desc: what's being tested |
| test(function() { |
| var a = document.createElement("a"); // <a> uses document encoding for URL's query |
| a.href = "https://example.com/?" + input; |
| result = a.search.substr(1); // remove leading "?" |
| assert_equals(result, expected); |
| }, desc); |
| } |
| |
| // create a simple list of just those code points for which there is no encoding is possible, from a representative subset of the BMP |
| codepoints = []; |
| |
| for (i = 0x4e00; i < 0x9fba; i++) { |
| result = big5Encoder(String.fromCodePoint(i)); |
| if (!result) { |
| var item = {}; |
| codepoints.push(item); |
| item.cp = i; |
| item.expected = "%26%23" + item.cp + "%3B"; |
| item.desc = "cjk "; |
| } |
| } |
| |
| for (i = 0xf900; i < 0xfa6e; i++) { |
| // compatibility |
| result = big5Encoder(String.fromCodePoint(i)); |
| if (!result) { |
| var item = {}; |
| codepoints.push(item); |
| item.cp = i; |
| item.expected = "%26%23" + item.cp + "%3B"; |
| item.desc = "compatibility "; |
| } |
| } |
| |
| for (i = 0xfa70; i < 0xfada; i++) { |
| result = big5Encoder(String.fromCodePoint(i)); |
| if (!result) { |
| var item = {}; |
| codepoints.push(item); |
| item.cp = i; |
| item.expected = "%26%23" + item.cp + "%3B"; |
| item.desc = "compatibility "; |
| } |
| } |
| |
| for (i = 0x3400; i < 0x4dbf; i++) { |
| // cjk extension A |
| result = big5Encoder(String.fromCodePoint(i)); |
| if (!result) { |
| var item = {}; |
| codepoints.push(item); |
| item.cp = i; |
| item.expected = "%26%23" + item.cp + "%3B"; |
| item.desc = "extension A "; |
| } |
| } |
| |
| // run the tests |
| for (var x = 0; x < codepoints.length; x++) { |
| encode( |
| String.fromCodePoint(codepoints[x].cp), |
| codepoints[x].expected, |
| codepoints[x].desc + |
| " U+" + |
| codepoints[x].cp.toString(16).toUpperCase() + |
| " " + |
| String.fromCodePoint(codepoints[x].cp) + |
| " " + |
| codepoints[x].expected |
| ); |
| } |
| |
| // NOTES |
| // this test relies on support for String.fromCodePoint, which appears to be supported by major desktop browsers |
| // the test excludes ASCII characters |
| </script> |
| </head> |
| <body> |
| <div id="log"></div> |
| </body> |
| </html> |