blob: 91959206b38637863f02ea670922b94ceec4873d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
<!DOCTYPE html>
<html>
<head>
<meta charset=big5> <!-- test breaks if the server overrides this -->
<title>Big5 encoding ASCII</title>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.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 the characters when encoding ASCII in a Big5-encoded document.">
</head>
<body>
<div id=log></div>
<script>
// index is Big5 index pointer, value is Unicode codepoint (dec)
function encode(input, output, desc) {
// tests whether a Unicode character is converted to an equivalent Big5 %-encoded byte sequence by href
// input: a escaped Unicode code point from the list of characters in the Big5 index
// output: expected percent-encoded byte sequence for the code point's equivalent in Big5 encoding
// desc: what's being tested
test(function() {
var a = document.createElement("a"); // <a> uses document encoding for URL's query
// Append and prepend x to test for off-by-one errors
a.href = "https://example.com/?x" + input + "x";
assert_true(
a.search.substr(1) == "x" + output + "x" ||
a.search.substr(1) == "x" + input + "x"
); // remove leading "?"
}, "big5 encoder: " + desc);
}
// test ASCII - test separately for chars that aren't escaped
for (var a = 0; a < 0x7f; a++) {
// The first 3 are stripped from URLs and the last is # which introduces a new URL segment
if (a === 0x09 || a === 0x0a || a === 0x0d || a === 0x23) {
continue;
}
hex = a.toString(16).toUpperCase();
while (hex.length < 2) {
hex = "0" + hex;
}
encode(
String.fromCharCode(a),
"%" + hex,
"test for ASCII codepoint 0x" +
a.toString(16) +
" " +
String.fromCharCode(a)
);
}
</script>
</body>
</html>
|