File tree 3 files changed +50
-48
lines changed
3 files changed +50
-48
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ class Request {
80
80
81
81
if ( typeof method !== 'string' ) {
82
82
throw new InvalidArgumentError ( 'method must be a string' )
83
- } else if ( tokenRegExp . exec ( method ) === null ) {
83
+ } else if ( ! util . isValidHTTPToken ( method ) ) {
84
84
throw new InvalidArgumentError ( 'invalid request method' )
85
85
}
86
86
Original file line number Diff line number Diff line change @@ -442,6 +442,52 @@ function toUSVString (val) {
442
442
return `${ val } `
443
443
}
444
444
445
+ /**
446
+ * @see https://tools.ietf.org/html/rfc7230#section-3.2.6
447
+ * @param {number } c
448
+ */
449
+ function isTokenCharCode ( c ) {
450
+ switch ( c ) {
451
+ case 0x22 :
452
+ case 0x28 :
453
+ case 0x29 :
454
+ case 0x2c :
455
+ case 0x2f :
456
+ case 0x3a :
457
+ case 0x3b :
458
+ case 0x3c :
459
+ case 0x3d :
460
+ case 0x3e :
461
+ case 0x3f :
462
+ case 0x40 :
463
+ case 0x5b :
464
+ case 0x5c :
465
+ case 0x5d :
466
+ case 0x7b :
467
+ case 0x7d :
468
+ // DQUOTE and "(),/:;<=>?@[\]{}"
469
+ return false
470
+ default :
471
+ // VCHAR %x21-7E
472
+ return c >= 0x21 && c <= 0x7e
473
+ }
474
+ }
475
+
476
+ /**
477
+ * @param {string } characters
478
+ */
479
+ function isValidHTTPToken ( characters ) {
480
+ if ( characters . length === 0 ) {
481
+ return false
482
+ }
483
+ for ( let i = 0 ; i < characters . length ; ++ i ) {
484
+ if ( ! isTokenCharCode ( characters . charCodeAt ( i ) ) ) {
485
+ return false
486
+ }
487
+ }
488
+ return true
489
+ }
490
+
445
491
// Parsed accordingly to RFC 9110
446
492
// https://www.rfc-editor.org/rfc/rfc9110#field.content-range
447
493
function parseRangeHeader ( range ) {
@@ -490,6 +536,8 @@ module.exports = {
490
536
isFormDataLike,
491
537
buildURL,
492
538
addAbortListener,
539
+ isValidHTTPToken,
540
+ isTokenCharCode,
493
541
parseRangeHeader,
494
542
nodeMajor,
495
543
nodeMinor,
Original file line number Diff line number Diff line change 3
3
const { redirectStatusSet, referrerPolicySet : referrerPolicyTokens , badPortsSet } = require ( './constants' )
4
4
const { getGlobalOrigin } = require ( './global' )
5
5
const { performance } = require ( 'perf_hooks' )
6
- const { isBlobLike, toUSVString, ReadableStreamFrom } = require ( '../core/util' )
6
+ const { isBlobLike, toUSVString, ReadableStreamFrom, isValidHTTPToken } = require ( '../core/util' )
7
7
const assert = require ( 'assert' )
8
8
const { isUint8Array } = require ( 'util/types' )
9
9
@@ -103,52 +103,6 @@ function isValidReasonPhrase (statusText) {
103
103
return true
104
104
}
105
105
106
- /**
107
- * @see https://tools.ietf.org/html/rfc7230#section-3.2.6
108
- * @param {number } c
109
- */
110
- function isTokenCharCode ( c ) {
111
- switch ( c ) {
112
- case 0x22 :
113
- case 0x28 :
114
- case 0x29 :
115
- case 0x2c :
116
- case 0x2f :
117
- case 0x3a :
118
- case 0x3b :
119
- case 0x3c :
120
- case 0x3d :
121
- case 0x3e :
122
- case 0x3f :
123
- case 0x40 :
124
- case 0x5b :
125
- case 0x5c :
126
- case 0x5d :
127
- case 0x7b :
128
- case 0x7d :
129
- // DQUOTE and "(),/:;<=>?@[\]{}"
130
- return false
131
- default :
132
- // VCHAR %x21-7E
133
- return c >= 0x21 && c <= 0x7e
134
- }
135
- }
136
-
137
- /**
138
- * @param {string } characters
139
- */
140
- function isValidHTTPToken ( characters ) {
141
- if ( characters . length === 0 ) {
142
- return false
143
- }
144
- for ( let i = 0 ; i < characters . length ; ++ i ) {
145
- if ( ! isTokenCharCode ( characters . charCodeAt ( i ) ) ) {
146
- return false
147
- }
148
- }
149
- return true
150
- }
151
-
152
106
/**
153
107
* @see https://fetch.spec.whatwg.org/#header-name
154
108
* @param {string } potentialValue
You can’t perform that action at this time.
0 commit comments