GeezerVison is showing github.com — Explicitly handle case where keyword encountered before alias value f… · phpmyadmin/sql-parser@f72a44c
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/Components/CaseExpression.php +10-8Lines changed: 10 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -227,16 +227,21 @@ public static function parse(Parser $parser, TokensList $list, array $options = |
227 | 227 | && $token->keyword === 'AS'){ |
228 | 228 |
|
229 | 229 | 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); |
234 | 231 | break; |
235 | 232 | } |
236 | 233 | $asFound = true; |
237 | 234 | continue; |
238 | 235 | } |
239 | 236 |
|
| 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 | + |
240 | 245 | if ($asFound |
241 | 246 | || $token->type === Token::TYPE_STRING |
242 | 247 | || ($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 = |
257 | 262 | break; |
258 | 263 | } |
259 | 264 | 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]); |
264 | 266 | } |
265 | 267 |
|
266 | 268 |
|
|