Skip to content

Commit

Permalink
Avoid decoding XHR type="json" responses as UTF-16BE/LE
Browse files Browse the repository at this point in the history
https://infra.spec.whatwg.org/#parse-json-from-bytes says to use
"UTF-8 decode" rather than "decode", so UTF-16BE/LE BOM should
not be honored.

Upstreamed from servo/servo#19096 [ci skip]
  • Loading branch information
hsivonen authored and jdm committed Nov 15, 2017
1 parent 32ea1aa commit 678d58c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions XMLHttpRequest/no-utf16-json.htm
@@ -0,0 +1,19 @@
<!doctype html>
<meta charset=utf-8>
<title>XMLHttpRequest: responseType "json" should be decoded as UTF-8 even when there's a UTF-16 BOM</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://infra.spec.whatwg.org/#parse-json-from-bytes" data-tested-assertations="following::ol/li[1]" />
<div id="log"></div>

<script>
async_test(function() {
var client = new XMLHttpRequest();
client.responseType = 'json';
client.onload = this.step_func_done(function(e) {
assert_equals(client.response, null);
});
client.open("GET", "resources/utf16-bom.json");
client.send(null);
}, 'JSON asa UTF-16 with BOM should decode as UTF-8 (and, therefore, fail)');
</script>
Binary file added XMLHttpRequest/resources/utf16-bom.json
Binary file not shown.

0 comments on commit 678d58c

Please sign in to comment.