11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<html> 31cb0ef41Sopenharmony_ci<head> 41cb0ef41Sopenharmony_ci<meta charset=big5> <!-- test breaks if the server overrides this --> 51cb0ef41Sopenharmony_ci<title>Big5 encoding ASCII</title> 61cb0ef41Sopenharmony_ci<meta name="timeout" content="long"> 71cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 81cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 91cb0ef41Sopenharmony_ci<link rel='author' title='Richard Ishida' href='mailto:ishida@w3.org'> 101cb0ef41Sopenharmony_ci<link rel='help' href='https://encoding.spec.whatwg.org/#big5'> 111cb0ef41Sopenharmony_ci<meta name="assert" content="The browser produces the characters when encoding ASCII in a Big5-encoded document."> 121cb0ef41Sopenharmony_ci</head> 131cb0ef41Sopenharmony_ci<body> 141cb0ef41Sopenharmony_ci<div id=log></div> 151cb0ef41Sopenharmony_ci<script> 161cb0ef41Sopenharmony_ci// index is Big5 index pointer, value is Unicode codepoint (dec) 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cifunction encode(input, output, desc) { 191cb0ef41Sopenharmony_ci // tests whether a Unicode character is converted to an equivalent Big5 %-encoded byte sequence by href 201cb0ef41Sopenharmony_ci // input: a escaped Unicode code point from the list of characters in the Big5 index 211cb0ef41Sopenharmony_ci // output: expected percent-encoded byte sequence for the code point's equivalent in Big5 encoding 221cb0ef41Sopenharmony_ci // desc: what's being tested 231cb0ef41Sopenharmony_ci test(function() { 241cb0ef41Sopenharmony_ci var a = document.createElement("a"); // <a> uses document encoding for URL's query 251cb0ef41Sopenharmony_ci // Append and prepend x to test for off-by-one errors 261cb0ef41Sopenharmony_ci a.href = "https://example.com/?x" + input + "x"; 271cb0ef41Sopenharmony_ci assert_true( 281cb0ef41Sopenharmony_ci a.search.substr(1) == "x" + output + "x" || 291cb0ef41Sopenharmony_ci a.search.substr(1) == "x" + input + "x" 301cb0ef41Sopenharmony_ci ); // remove leading "?" 311cb0ef41Sopenharmony_ci }, "big5 encoder: " + desc); 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci// test ASCII - test separately for chars that aren't escaped 351cb0ef41Sopenharmony_cifor (var a = 0; a < 0x7f; a++) { 361cb0ef41Sopenharmony_ci // The first 3 are stripped from URLs and the last is # which introduces a new URL segment 371cb0ef41Sopenharmony_ci if (a === 0x09 || a === 0x0a || a === 0x0d || a === 0x23) { 381cb0ef41Sopenharmony_ci continue; 391cb0ef41Sopenharmony_ci } 401cb0ef41Sopenharmony_ci hex = a.toString(16).toUpperCase(); 411cb0ef41Sopenharmony_ci while (hex.length < 2) { 421cb0ef41Sopenharmony_ci hex = "0" + hex; 431cb0ef41Sopenharmony_ci } 441cb0ef41Sopenharmony_ci encode( 451cb0ef41Sopenharmony_ci String.fromCharCode(a), 461cb0ef41Sopenharmony_ci "%" + hex, 471cb0ef41Sopenharmony_ci "test for ASCII codepoint 0x" + 481cb0ef41Sopenharmony_ci a.toString(16) + 491cb0ef41Sopenharmony_ci " " + 501cb0ef41Sopenharmony_ci String.fromCharCode(a) 511cb0ef41Sopenharmony_ci ); 521cb0ef41Sopenharmony_ci} 531cb0ef41Sopenharmony_ci</script> 541cb0ef41Sopenharmony_ci</body> 551cb0ef41Sopenharmony_ci</html> 56