File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,8 @@ const headersForPath = function (rules, path) {
6767 return pathObject
6868}
6969
70+ const HEADER_SEPARATOR = ':'
71+
7072const parseHeadersFile = function ( filePath ) {
7173 if ( ! fs . existsSync ( filePath ) ) {
7274 return { }
@@ -94,9 +96,9 @@ const parseHeadersFile = function (filePath) {
9496 throw new Error ( 'path should come before headers' )
9597 }
9698
97- if ( line . includes ( ':' ) ) {
98- const [ key = '' , value = '' ] = line . split ( ':' , 2 )
99- const [ trimmedKey , trimmedValue ] = [ key . trim ( ) , value . trim ( ) ]
99+ if ( line . includes ( HEADER_SEPARATOR ) ) {
100+ const [ key = '' , ... value ] = line . split ( HEADER_SEPARATOR )
101+ const [ trimmedKey , trimmedValue ] = [ key . trim ( ) , value . join ( HEADER_SEPARATOR ) . trim ( ) ]
100102 if ( trimmedKey . length === 0 || trimmedValue . length === 0 ) {
101103 throw new Error ( `invalid header at line: ${ index } \n${ line } \n` )
102104 }
Original file line number Diff line number Diff line change @@ -35,6 +35,10 @@ const headers = [
3535 path : '/directory/*/test.html' ,
3636 headers : [ 'X-Frame-Options: test' ] ,
3737 } ,
38+ {
39+ path : '/with-colon' ,
40+ headers : [ 'Custom-header: http://www.example.com' ] ,
41+ } ,
3842]
3943
4044test . before ( async ( t ) => {
@@ -99,6 +103,9 @@ test('_headers: validate rules', (t) => {
99103 '/directory/*/test.html' : {
100104 'X-Frame-Options' : [ 'test' ] ,
101105 } ,
106+ '/with-colon' : {
107+ 'Custom-header' : [ 'http://www.example.com' ] ,
108+ } ,
102109 } )
103110} )
104111
You can’t perform that action at this time.
0 commit comments