Skip to content

Commit

Permalink
XMLHttpRequest: response header value containing 0x00
Browse files Browse the repository at this point in the history
As discussed in whatwg/xhr#165 these should turn the response into a network error.
  • Loading branch information
annevk committed Apr 11, 2018
1 parent 7967c43 commit 74c1042
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions xhr/headers-normalize-response.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
<title>Whitespace and null in header values</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js?pipe=sub></script>

<h1>Whitespace and null in response header values</h1>

<div id=log></div>

<script>
function error(val) {
test(() => {
const client = new XMLHttpRequest();
client.open("GET", "resources/parse-headers.py?my-custom-header="+encodeURIComponent(val), false);
assert_throws("NetworkError", () => client.send());
}, "Header value: " + val.replace("\0", "\\0"));
}

function matchHeaderValue(val) {
test(function () {
Expand All @@ -20,12 +22,12 @@ <h1>Whitespace and null in response header values</h1>
var r = client.getResponseHeader("My-Custom-Header");

assert_equals(r, trimmed);
}, "Header value: " + val.replace(/\t/g, "[tab]").replace(/ /g, "_").replace("\0", "\\0"));
}, "Header value: " + val.replace(/\t/g, "[tab]").replace(/ /g, "_"));
}

matchHeaderValue("hello world\0");
matchHeaderValue("\0hello world");
matchHeaderValue("hello\0world");
error("hello world\0");
error("\0hello world");
error("hello\0world");
matchHeaderValue(" hello world");
matchHeaderValue("hello world ");
matchHeaderValue(" hello world ");
Expand All @@ -34,9 +36,12 @@ <h1>Whitespace and null in response header values</h1>
matchHeaderValue("\thello world\t");
matchHeaderValue("hello world");
matchHeaderValue("hello\tworld");
matchHeaderValue("\0");
error("\0");
matchHeaderValue(" ");
matchHeaderValue("\t");
matchHeaderValue("");

promise_test(t => {
return promise_rejects(t, new TypeError(), fetch("resources/parse-headers.py?my-custom-header="+encodeURIComponent("x\0x")));
}, "Ensure fetch() rejects too")
</script>

0 comments on commit 74c1042

Please sign in to comment.