Skip to content

Commit 76abbfe

Browse files
committed
Updated Lexer PREG to allow only a single ptionnal space after a comma token
1 parent ed676d0 commit 76abbfe

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/TypeResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function resolve($type, Context $context = null)
115115
}
116116

117117
// split the type string into tokens `|`, `?`, `<`, `>`, `,`, `(`, `)[]`, '<', '>' and type names
118-
$tokens = preg_split('/\s*(\\||\\?|<|>|,|\\(|\\)(?:\\[\\])+)\s*/', $type, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
118+
$tokens = preg_split('/(\\||\\?|<|>|, ?|\\(|\\)(?:\\[\\])+)/', $type, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
119119
$tokenIterator = new \ArrayIterator($tokens);
120120

121121
return $this->parseTypes($tokenIterator, $context, self::PARSER_IN_COMPOUND);
@@ -198,7 +198,7 @@ private function parseTypes(\ArrayIterator $tokens, Context $context, $parserCon
198198

199199
$tokens->next();
200200
} elseif ($parserContext === self::PARSER_IN_COLLECTION_EXPRESSION
201-
&& ($token === '>' || $token === ',')
201+
&& ($token === '>' || trim($token) === ',')
202202
) {
203203
break;
204204
} else {
@@ -407,7 +407,7 @@ private function resolveCollection(\ArrayIterator $tokens, Type $classType, Cont
407407
$valueType = $this->parseTypes($tokens, $context, self::PARSER_IN_COLLECTION_EXPRESSION);
408408
$keyType = null;
409409

410-
if ($tokens->current() === ',') {
410+
if ($tokens->current() !== null && trim($tokens->current()) === ',') {
411411
// if we have a comma, then we just parsed the key type, not the value type
412412
$keyType = $valueType;
413413
if ($isArray) {

0 commit comments

Comments
 (0)