Skip to content

Commit

Permalink
escape single quotes in sql generator
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Jan 12, 2024
1 parent 778bc5a commit 7b1cbce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Changelog
2.x
---

2.0.1
-----

* The SQL generator now escapes single quotes `'`. This avoids SQL injection risks. If you escaped
strings manually (by duplicating the `'`) you will need to stop doing that as otherwise the query
will be run with duplicated single quotes.

2.0.0
-----

Expand Down
2 changes: 1 addition & 1 deletion src/PHPCR/Util/QOM/BaseSqlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function evalLiteral(mixed $literal): string
return $this->evalCastLiteral($string, 'DOUBLE');
}

return "'$literal'";
return sprintf("'%s'", str_replace("'", "''", $literal));
}

/**
Expand Down

0 comments on commit 7b1cbce

Please sign in to comment.