Skip to content

Commit f72a44c

Browse files
committed
Explicitly handle case where keyword encountered before alias value found
1 parent f2127a1 commit f72a44c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

‎src/Components/CaseExpression.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,21 @@ public static function parse(Parser $parser, TokensList $list, array $options =
227227
&& $token->keyword === 'AS'){
228228

229229
if ($asFound || !empty($ret->alias)) {
230-
$parser->error(
231-
'Potential duplicate alias of CASE expression.',
232-
$token
233-
);
230+
$parser->error('Potential duplicate alias of CASE expression.', $token);
234231
break;
235232
}
236233
$asFound = true;
237234
continue;
238235
}
239236

237+
if ($asFound
238+
&& $token->type === Token::TYPE_KEYWORD
239+
&& ($token->flags & Token::FLAG_KEYWORD_RESERVED || $token->flags & Token::FLAG_KEYWORD_FUNCTION)){
240+
$parser->error('An alias expected after AS but got '.$token->value, $token);
241+
$asFound = false;
242+
break;
243+
}
244+
240245
if ($asFound
241246
|| $token->type === Token::TYPE_STRING
242247
|| ($token->type === Token::TYPE_SYMBOL && !$token->flags & Token::FLAG_SYMBOL_VARIABLE)
@@ -257,10 +262,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
257262
break;
258263
}
259264
if ($asFound) {
260-
$parser->error(
261-
'An alias was expected after AS.',
262-
$list->tokens[$list->idx - 1]
263-
);
265+
$parser->error('An alias was expected after AS.', $list->tokens[$list->idx - 1]);
264266
}
265267

266268

0 commit comments

Comments
 (0)