@@ -242,57 +242,15 @@ function checkIsHttpToken(val) {
242
242
return tokenRegExp . test ( val ) ;
243
243
}
244
244
245
+ const headerCharRegex = / [ ^ \t \x20 - \x7e \x80 - \xff ] / ;
245
246
/**
246
247
* True if val contains an invalid field-vchar
247
248
* field-value = *( field-content / obs-fold )
248
249
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
249
250
* field-vchar = VCHAR / obs-text
250
- *
251
- * checkInvalidHeaderChar() is currently designed to be inlinable by v8,
252
- * so take care when making changes to the implementation so that the source
253
- * code size does not exceed v8's default max_inlined_source_size setting.
254
251
**/
255
- var validHdrChars = [
256
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , // 0 - 15
257
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // 16 - 31
258
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , // 32 - 47
259
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , // 48 - 63
260
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , // 64 - 79
261
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , // 80 - 95
262
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , // 96 - 111
263
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , // 112 - 127
264
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , // 128 ...
265
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
266
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
267
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
268
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
269
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
270
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
271
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 // ... 255
272
- ] ;
273
252
function checkInvalidHeaderChar ( val ) {
274
- val += '' ;
275
- if ( val . length < 1 )
276
- return false ;
277
- if ( ! validHdrChars [ val . charCodeAt ( 0 ) ] )
278
- return true ;
279
- if ( val . length < 2 )
280
- return false ;
281
- if ( ! validHdrChars [ val . charCodeAt ( 1 ) ] )
282
- return true ;
283
- if ( val . length < 3 )
284
- return false ;
285
- if ( ! validHdrChars [ val . charCodeAt ( 2 ) ] )
286
- return true ;
287
- if ( val . length < 4 )
288
- return false ;
289
- if ( ! validHdrChars [ val . charCodeAt ( 3 ) ] )
290
- return true ;
291
- for ( var i = 4 ; i < val . length ; ++ i ) {
292
- if ( ! validHdrChars [ val . charCodeAt ( i ) ] )
293
- return true ;
294
- }
295
- return false ;
253
+ return headerCharRegex . test ( val ) ;
296
254
}
297
255
298
256
module . exports = {
0 commit comments