Arithmetic expression inside greatest() leads to infinite parsing loop
sjuvonen opened this issue · comments
Samu Juvonen commented
I noticed that using an arithmetic operation inside greatest() causes parser to enter an infinite loop.
My doctrine/dbal
is at version 2.12.1
.
Consider this working example:
$result = $this->doctrine
->getManagerForClass(Foo::class)
->createQueryBuilder()
// Here e.g. "sqrt(30) * 100" triggers infinite loop but plain "sqrt(30)" will work just fine.
->select('
greatest(
sqrt(30) * 100,
sqrt(11) * 150
)
AS score
')
->from(Foo::class, 'a')
->getQuery()
->getResult()
;
var_dump($result);
My understanding of the parser is limited but I managed to make this behavior stop by overriding $commonNodeMapping
in Greatest.php
. I have no idea what this will break in exchange...
class Greatest extends BaseVariadicFunction
{
// Default seems to be 'StringPrimary'.
protected $commonNodeMapping = 'SimpleArithmeticExpression';
protected function customiseFunction(): void
{
$this->setFunctionPrototype('greatest(%s)');
}
}
Martin Georgiev commented
Thanks for reporting this. Do you mind opening a PR with your proposed solution?