@@ -272,7 +272,7 @@ private static function parseString(ParsingInput $input): string
272
272
}
273
273
} elseif ($ char === '" ' ) {
274
274
return $ output ;
275
- } elseif (ord ($ char ) <= 0x1f || ord ( $ char ) >= 0x7f ) {
275
+ } elseif (! ctype_print ($ char )) {
276
276
throw new ParseException ('Invalid character in string at position ' . ($ input ->position () - 1 ));
277
277
}
278
278
@@ -298,18 +298,21 @@ private static function parseDisplayString(ParsingInput $string): DisplayString
298
298
while (!$ string ->empty ()) {
299
299
$ char = $ string ->consumeChar ();
300
300
301
- if (ord ($ char ) <= 0x1f || ord ( $ char ) >= 0x7f ) {
301
+ if (! ctype_print ($ char )) {
302
302
throw new ParseException (
303
303
'Invalid character in display string at position ' . ($ string ->position () - 1 )
304
304
);
305
305
} elseif ($ char === '% ' ) {
306
- try {
307
- $ encodedString .= '% ' . $ string ->consumeRegex ('/^[0-9a-f]{2}/ ' );
308
- } catch (\RuntimeException ) {
306
+ if ($ string ->remainingLength () < 2 ) {
307
+ break ;
308
+ }
309
+ $ encodedChar = $ string ->consume (2 );
310
+ if (!ctype_xdigit ($ encodedChar ) || ctype_upper ($ encodedChar )) {
309
311
throw new ParseException (
310
312
'Invalid hex values in display string at position ' . ($ string ->position () - 1 )
311
313
);
312
314
}
315
+ $ encodedString .= '% ' . $ encodedChar ;
313
316
} elseif ($ char === '" ' ) {
314
317
$ displayString = new DisplayString (rawurldecode ($ encodedString ));
315
318
// An invalid UTF-8 subject will cause the preg_* function to match nothing.
0 commit comments