3
3
< title > Whitespace and null in header values</ title >
4
4
< script src =/resources/testharness.js > </ script >
5
5
< script src =/resources/testharnessreport.js > </ script >
6
- < script src =support.js?pipe =sub> </ script >
7
-
8
- < h1 > Whitespace and null in response header values</ h1 >
9
-
10
6
< div id =log > </ div >
11
-
12
7
< script >
8
+ function error ( val ) {
9
+ test ( ( ) => {
10
+ const client = new XMLHttpRequest ( ) ;
11
+ client . open ( "GET" , "resources/parse-headers.py?my-custom-header=" + encodeURIComponent ( val ) , false ) ;
12
+ assert_throws ( "NetworkError" , ( ) => client . send ( ) ) ;
13
+ } , "Header value: " + val . replace ( "\0" , "\\0" ) ) ;
14
+ }
13
15
14
16
function matchHeaderValue ( val ) {
15
17
test ( function ( ) {
@@ -20,12 +22,12 @@ <h1>Whitespace and null in response header values</h1>
20
22
var r = client . getResponseHeader ( "My-Custom-Header" ) ;
21
23
22
24
assert_equals ( r , trimmed ) ;
23
- } , "Header value: " + val . replace ( / \t / g, "[tab]" ) . replace ( / / g, "_" ) . replace ( "\0" , "\\0" ) ) ;
25
+ } , "Header value: " + val . replace ( / \t / g, "[tab]" ) . replace ( / / g, "_" ) ) ;
24
26
}
25
27
26
- matchHeaderValue ( "hello world\0" ) ;
27
- matchHeaderValue ( "\0hello world" ) ;
28
- matchHeaderValue ( "hello\0world" ) ;
28
+ error ( "hello world\0" ) ;
29
+ error ( "\0hello world" ) ;
30
+ error ( "hello\0world" ) ;
29
31
matchHeaderValue ( " hello world" ) ;
30
32
matchHeaderValue ( "hello world " ) ;
31
33
matchHeaderValue ( " hello world " ) ;
@@ -34,9 +36,12 @@ <h1>Whitespace and null in response header values</h1>
34
36
matchHeaderValue ( "\thello world\t" ) ;
35
37
matchHeaderValue ( "hello world" ) ;
36
38
matchHeaderValue ( "hello\tworld" ) ;
37
- matchHeaderValue ( "\0" ) ;
39
+ error ( "\0" ) ;
38
40
matchHeaderValue ( " " ) ;
39
41
matchHeaderValue ( "\t" ) ;
40
42
matchHeaderValue ( "" ) ;
41
43
44
+ promise_test ( t => {
45
+ return promise_rejects ( t , new TypeError ( ) , fetch ( "resources/parse-headers.py?my-custom-header=" + encodeURIComponent ( "x\0x" ) ) ) ;
46
+ } , "Ensure fetch() rejects too" )
42
47
</ script >
0 commit comments