Closed sgtwinters closed 6 years ago
Hey @sgtwinters thank you very much for your issue.
Can you give an example how you call the QueryMapper
? E.g., can you provide the URL you are calling (with params)?
Hi @johannesschobel, yes off course. I don't call the QueryMapper directly by the way, this is a short snippet.
public function getProcesses(Request $request)
{
$processes = Process::all();
$filter = new DingoQueryMapper($request);
$processes = $filter->createFromCollection($processes)->paginate();
return $this->response->paginator($processes, new ProcessTransformer);
}
The issue arises when an item within the (in this case) $processes collection includes the single quotes I mentioned before.
Thanks in advance!
Hey man.. And can you give me an example of the Process
data? What do you mean with "single quoted data"?
I use it, for example, like this:
GET /users?name=jo*
This would get any user, that starts with jo
...
Do you mean the following thing:
Your $process->name
may look like this : $process->name = "hello'world";
(note the quote!)
And now you are trying to get
GET /processes?name=hello'world
Maybe you need to escape the '
?
aaaaaaaaaaaaaah.. ok.. i just tried it myself - you may be right.. I get a ParseError
.. Is it this, what you meant?
Hey Johannes, exactly like you just made as an example: the $process->name in my case includes two quotes $process->name = "Hi 'test'"
(but that will cause the same problem).
The rule built in createEvaluationRule
(the substr) will in that case include unescaped single quotes, therefore forming a invalid substr() method (at least thats where I ended up before creating this issue :)):
$rule = "substr('%s', 0, strlen('%s')) %s '%s'"
can you provide me with a PR to fix this? ;)
Hey @johannesschobel, I will look into it a bit further asap :) and if I fix it (properly) I will provide a PR. Thnx for now!
Thank you for noticing this issue and reporting it! Will look forward for your PR
I encountered an issue when filtering a Collection using the createFromCollection method from your DingoQueryMapper. When there are model params with single quoted content, building the filtering rules seems to break.
I think the problem is in the createEvaluationRule method from the CollectionOperator. When building an evaluation rule, where the key contains a single quote, the endresult is a string which cannot be evaluated. I can solve this by stripping any single quotes from the $key parameter, before further building the rule in createEvaluationRule.
Just to be sure, am I doing something wrong here or did I just found a bug ;). Thanks in advance!