| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="iso-2022-jp"> <!-- test breaks if the server overrides this --> |
| <title>ISO 2022 JP encoding errors (form, han)</title> |
| <meta name="timeout" content="long"> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <script src="jis0208_index.js"></script> |
| <script src="iso2022jp-encoder.js"></script> |
| <link rel="author" title="Richard Ishida" href="mailto:ishida@w3.org"> |
| <link rel="help" href="https://encoding.spec.whatwg.org/#iso-2022-jp"> |
| <meta name="assert" content="The browser produces percent-escaped character references for a URL produced by a form when encoding han characters that are not in the iso-2022-jp encoding."> |
| <style> |
| iframe { display:none } |
| form { display:none } |
| </style> |
| </head> |
| <body> |
| <div id="log"></div> |
| <script> |
| var tests = []; |
| var cplist = []; |
| var numTests = null; |
| var numFrames = 2; |
| var chunkSize = 400; |
| var numChunks = null; |
| var frames = null; |
| var frames = null; |
| var forms = null; |
| var seperator = "\u0019"; |
| var encodedSeperator = encodeURIComponent("\u0019"); |
| var currentChunkIndex = 0; |
| |
| setup(function() { |
| // set up a simple array of unicode codepoints that are not encoded |
| var codepoints = []; |
| |
| for (i = 0x4e00; i < 0x9fba; i++) { |
| result = iso2022jpEncoder(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 = iso2022jpEncoder(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 = iso2022jpEncoder(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 = iso2022jpEncoder(String.fromCodePoint(i)); |
| if (!result) { |
| var item = {}; |
| codepoints.push(item); |
| item.cp = i; |
| item.expected = "%26%23" + item.cp + "%3B"; |
| item.desc = "extension A "; |
| } |
| } |
| |
| // convert the information into a simple array of objects that can be easily traversed |
| var currentChunk = []; |
| var currentTests = []; |
| cplist = [currentChunk]; |
| tests = [currentTests]; |
| for (i = 0; i < codepoints.length; i++) { |
| if (currentChunk.length == chunkSize) { |
| currentChunk = []; |
| cplist.push(currentChunk); |
| currentTests = []; |
| tests.push(currentTests); |
| } |
| var item = {}; |
| currentChunk.push(item); |
| item.cp = codepoints[i].cp; |
| item.expected = codepoints[i].expected; |
| item.desc = codepoints[i].desc; |
| currentTests.push( |
| async_test( |
| item.desc + |
| " U+" + |
| item.cp.toString(16).toUpperCase() + |
| " " + |
| String.fromCodePoint(item.cp) + |
| " " + |
| normalizeStr(item.expected) |
| ) |
| ); |
| } |
| |
| numChunks = cplist.length; |
| |
| for (var i = 0; i < numFrames; i++) { |
| var frame = document.createElement("iframe"); |
| frame.id = frame.name = "frame-" + i; |
| document.body.appendChild(frame); |
| var form = document.createElement("form"); |
| form.id = "form-" + i; |
| form.method = "GET"; |
| form.action = "/common/blank.html"; |
| form.acceptCharset = "iso-2022-jp"; |
| form.target = frame.id; |
| var input = document.createElement("input"); |
| input.id = input.name = "input-" + i; |
| form.appendChild(input); |
| document.body.appendChild(form); |
| } |
| |
| addEventListener("load", function() { |
| frames = Array.prototype.slice.call( |
| document.getElementsByTagName("iframe") |
| ); |
| forms = Array.prototype.slice.call( |
| document.getElementsByTagName("form") |
| ); |
| inputs = Array.prototype.slice.call( |
| document.getElementsByTagName("input") |
| ); |
| for (var i = 0; i < Math.min(numFrames, numChunks); i++) { |
| runNext(i); |
| } |
| }); |
| }); |
| |
| function runNext(id) { |
| var i = currentChunkIndex; |
| currentChunkIndex += 1; |
| |
| var iframe = frames[id]; |
| var form = forms[id]; |
| var input = inputs[id]; |
| |
| input.value = cplist[i] |
| .map(function(x) { |
| return String.fromCodePoint(x.cp); |
| }) |
| .join(seperator); |
| form.submit(); |
| |
| iframe.onload = function() { |
| var url = iframe.contentWindow.location; |
| var query = url.search; |
| var result_string = query.substr(query.indexOf("=") + 1); |
| var results = result_string.split(encodedSeperator); |
| |
| for (var j = 0; j < cplist[i].length; j++) { |
| var t = tests[i][j]; |
| t.step(function() { |
| assert_equals(results[j], cplist[i][j].expected); |
| }); |
| t.done(); |
| } |
| if (currentChunkIndex < numChunks) { |
| runNext(id); |
| } |
| }; |
| } |
| </script> |
| </body> |
| </html> |