[Autocomplete] Fix LIKE ESCAPE clause breaking search on PostgreSQL#3685
Open
Amoifr wants to merge 1 commit into
Open
[Autocomplete] Fix LIKE ESCAPE clause breaking search on PostgreSQL#3685Amoifr wants to merge 1 commit into
Amoifr wants to merge 1 commit into
Conversation
The "ESCAPE '\'" clause added in 2.36 to escape LIKE wildcards produces
invalid SQL on PostgreSQL: with standard_conforming_strings=off the
backslash escapes the closing quote, breaking the statement (surfaces as
SQLSTATE[HY093] / [22025]).
Use a backslash-free escape character ("!") via the platform's
escapeStringForLike() instead. The explicit ESCAPE clause is kept since
SQLite has no default LIKE escape character.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since 2.36,
EntitySearchUtilescapes the LIKE wildcards (%,_) in theautocomplete search query and pairs that with an
ESCAPE '\'clause so theescaped wildcards are treated literally.
That backslash breaks on PostgreSQL: with
standard_conforming_strings = off(older setups / some PDO driver versions) the backslash escapes the closing
quote of the SQL string literal, producing invalid SQL. It surfaces as
SQLSTATE[HY093] Invalid parameter numberorSQLSTATE[22025] invalid escape stringand makes every text search throw.Fix
Use a backslash-free LIKE escape character (
!) via the platform'sescapeStringForLike(). The explicitESCAPEclause is kept on purpose:SQLite has no default LIKE escape character, so dropping it would silently
re-open the wildcard-injection the 2.36 hardening closed.
Tests
testItEscapesLikeWildcardsInTheQueryis extendedwith a literal
!case and stays green — it can only pass if theESCAPEclause works.
ESCAPE '\'errors with
standard_conforming_strings=off; the newESCAPE '!'worksunder both settings and correctly matches literal
%,_and!.