Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryException::formatMessage() replacing all question marks #39239

Closed
lupinitylabs opened this issue Oct 18, 2021 · 1 comment
Closed

QueryException::formatMessage() replacing all question marks #39239

lupinitylabs opened this issue Oct 18, 2021 · 1 comment

Comments

@lupinitylabs
Copy link
Contributor

lupinitylabs commented Oct 18, 2021

  • Laravel Version: 8.53.1
  • PHP Version: 8.0.11
  • Database Driver & Version: MySQL 8.0.26

Description:

The formatMessage() method in \Illuminate\Database\QueryException provides the failed query as SQL string with bindings replaced as follows:

        return $previous->getMessage().' (SQL: '.Str::replaceArray('?', $bindings, $sql).')';

This naive approach will of course replace ALL question marks within the query string, including question marks that may exist in parts of the query including, but not limited to raw statements (select, order, subqueries) or SQL comments.

However there are a couple of reasons not to act on this:

  • this issue exists since 8 years now, so I suppose it is not really a concern
  • it is only cosmetic.
  • fixing this is not trivial. Using a regex could mitigate the easy cases, but to really tackle this might require parsing.

Steps To Reproduce:

  User::selectRaw('"Hello??"')->whereType('SomeParameter')->find(4)

grafik

  User::selectRaw('"Test?" /* Some comment? */')->whereType('SomeParameter')->find(4)

grafik

@driesvints
Copy link
Member

Yeah, I don't really see a big issue here if it's been in here so long and no one has reported it so far. Appreciate you informing us however 👍 But I think we're gonna let this one be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants