File tree 2 files changed +19
-11
lines changed
2 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -334,16 +334,19 @@ private static function parseDisplayString(ParsingInput $string): DisplayString
334
334
*/
335
335
private static function parseToken (ParsingInput $ input ): Token
336
336
{
337
- // Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing
338
- // 3.2.6. Field Value Components
339
- // @see https://tools.ietf.org/html/rfc7230#section-3.2.6
340
- $ tchar = preg_quote ( "!#$%&'*+-.^_`|~ " ) ;
337
+ // RFC 9110: HTTP Semantics (5.6.2. Tokens)
338
+ // @see https://www.rfc-editor.org/rfc/rfc9110.html#name-tokens
339
+ // $tchar = preg_quote("!#$%&'*+-.^_`|~");
340
+ $ tchar = "!#$%&'*+\ -.^_`|~ " ;
341
341
342
342
// parseToken is only called by parseBareItem if the initial character
343
343
// is valid, so a Token object is always returned. If there is an
344
344
// invalid character in the token, the public function that was called
345
345
// will detect that the remainder of the input string is invalid.
346
- return new Token ($ input ->consumeRegex ('/^([a-z*][a-z0-9:\/ ' . $ tchar . ']*)/i ' ));
346
+ return new Token ($ input ->consumeRegex ('/^(
347
+ (?:\*|[a-z]) # an alphabetic character or "*"
348
+ [a-z0-9:\/ ' . $ tchar . ']* # zero to many token characters
349
+ )/ix ' ));
347
350
}
348
351
349
352
/**
Original file line number Diff line number Diff line change @@ -224,12 +224,17 @@ private static function serializeDisplayString(DisplayString $value): string
224
224
225
225
private static function serializeToken (Token $ value ): string
226
226
{
227
- // Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing
228
- // 3.2.6. Field Value Components
229
- // @see https://tools.ietf.org/html/rfc7230#section-3.2.6
230
- $ tchar = preg_quote ("!#$%&'*+-.^_`|~ " );
231
-
232
- if (!preg_match ('/^((?:\*|[a-z])[a-z0-9:\/ ' . $ tchar . ']*)$/i ' , (string ) $ value )) {
227
+ // RFC 9110: HTTP Semantics (5.6.2. Tokens)
228
+ // @see https://www.rfc-editor.org/rfc/rfc9110.html#name-tokens
229
+ // $tchar = preg_quote("!#$%&'*+-.^_`|~");
230
+ $ tchar = "!#$%&'*+\-.^_`|~ " ;
231
+
232
+ if (
233
+ !preg_match ('/^(
234
+ (?:\*|[a-z]) # an alphabetic character or "*"
235
+ [a-z0-9:\/ ' . $ tchar . ']* # zero to many token characters
236
+ )$/ix ' , (string ) $ value )
237
+ ) {
233
238
throw new SerializeException ('Invalid characters in token ' );
234
239
}
235
240
You can’t perform that action at this time.
0 commit comments