mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-3821: QueryBuilder throws QueryException when Expr\Comparison($x, 'LIKE', $y) with 'LIKE' operator was added in where clause #4681
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jul 13, 2015).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user eghlima.r@gmail.com:
This is the query from
QueryBuilder->getDQL():SELECT c FROM wsi\ams\model\Cell c INNER JOIN c.accountingUnit au WHERE 'name' LIKE ?1We are using YII (1.1.16) and Doctrine ORM (2.5).
For YII grid, we need to handle filtering. We accept user input and try to add them all to an Expr\orX clause then add this expression to our QueryBuilder object at the end.
The problem as i could understood is expr\like internally handle by expr\comparison. this comparison later will use in Parser class and in ComparisonOperator method, there is no case for LIKE in switch-case at all. but before that method in Parser class there is a method called: Parser::SimpleConditionalExpression and in this method there is:
and it should handle like in this clause (If i get it right?), but $token['type'] is holding attribute name(in my case
name) not the constant belong to Lexer::T_LIKE and so it ignores this clause and goes down into:Example of code that throws exception:
Exception details:
@doctrinebot commented on GitHub (Jul 13, 2015):
@doctrinebot commented on GitHub (Jul 13, 2015):
Comment created by eghlima.r@gmail.com:
Code i have sent for you is in this class file.
We use it as DataProvider for YII GridView.
When I was writing a sample code to do filter by using Expr, this bug has raised.
@doctrinebot commented on GitHub (Jul 13, 2015):
Comment created by eghlima.r@gmail.com:
This is our composer.json
we are using ORM version 2.5
@doctrinebot commented on GitHub (Jul 20, 2015):
Comment created by @ocramius:
Moved back to
Minor@doctrinebot commented on GitHub (Jul 20, 2015):
Comment created by @ocramius:
Note: I moved this to
Security Issues, because your code is vulnerable to SQL/DQL injections: fix it.This issue as-is is invalid and I'm going to close it, as you are misusing the query builder by even allowing
$_REQUESTto directly affect the generated query.The actual resolution for this issue is to allow the
LIKEoperator to behave like any other operator inf5e79fa0c0/lib/Doctrine/ORM/Query/Parser.php (L3280-L3287), which is an improvement (not a bug), since aComparisonOperatorcurrently doesn't also handleLIKE.@doctrinebot commented on GitHub (Jul 20, 2015):
Issue was closed with resolution "Invalid"
@doctrinebot commented on GitHub (Jul 20, 2015):
Comment created by @ocramius:
Also please check http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#ebnf
@doctrinebot commented on GitHub (Jul 20, 2015):
Comment created by eghlima.r@gmail.com:
Thank you Marco for your answer.
thank you for your notice, but sql injection is not my concern now, since it is sample code.
I think i did not misuse querybuilder! i just copied what is written in documentation here:
http://doctrine-orm.readthedocs.org/en/latest/reference/query-builder.html#high-level-api-methods
accordingly I wrote this (i made all things statically, so we don't have injection problem together) :
Should it work or not? it does not work for me.
it gives me the error i gave you with full stack. I think i could not explain clearly.
I am not using Expr\Comparison, i said, this code
$qb->expr()->like('u.nickname', '?2')which is written in documentation, internally is usingExpr\Comparisonand later in Parser class, thisLIKE(which is wrongly marked as comparison) is not handled and causes this error!So it is not an improvement, it is a bug. if you need more detail to simulate it, i am at your service.
BUT if i write this for
LIKEit will work!But i prefer the officially said and well structured way to add my LIKE expressions to querybuilder.
@doctrinebot commented on GitHub (Jul 20, 2015):
Comment created by eghlima.r@gmail.com:
Dear Marco
I just updated my vendor with composer and everything works fine!
But i am sure, that bug in previous comments was exist!
I just changed some lines in doctrine bootstrap and updated vendor.
Sorry about your time. but it is fixed now
@doctrinebot commented on GitHub (Jul 20, 2015):
Comment created by @ocramius:
No problem :-)
I'm keeping the issue hidden to the public though (until it's audited by your team).