Skip to content

Commit 8b10aae

Browse files
committed
Fixing the parser is not recognizing single chars x and y aliases or table names
Signed-off-by: iifawzi <[email protected]>
1 parent 0f4f8de commit 8b10aae

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Components/Expression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
225225
continue;
226226
}
227227

228-
if ($token->type === Token::TYPE_KEYWORD) {
228+
if ($token->type === Token::TYPE_KEYWORD && ($token->value !== 'x' && $token->value !== 'y')) {
229229
if (($brackets > 0) && empty($ret->subquery) && ! empty(Parser::$STATEMENT_PARSERS[$token->keyword])) {
230230
// A `(` was previously found and this keyword is the
231231
// beginning of a statement, so this is a subquery.

tests/Components/ExpressionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ public function testParse2(): void
2222
$this->assertEquals($component->expr, 'col');
2323
}
2424

25+
public function testParse3(): void
26+
{
27+
$component = Expression::parse(new Parser(), $this->getTokensList('col x'));
28+
$this->assertEquals($component->alias, 'x');
29+
30+
$component = Expression::parse(new Parser(), $this->getTokensList('col y'));
31+
$this->assertEquals($component->alias, 'y');
32+
33+
$component = Expression::parse(new Parser(), $this->getTokensList('x.col FROM (SELECT ev.col FROM ev) x'));
34+
$this->assertEquals($component->table, 'x');
35+
36+
$component = Expression::parse(new Parser(), $this->getTokensList('y.col FROM (SELECT ev.col FROM ev) y'));
37+
$this->assertEquals($component->table, 'y');
38+
}
39+
2540
/**
2641
* @dataProvider parseErrProvider
2742
*/

0 commit comments

Comments
 (0)