Repository navigation
fix: match LIKE wildcards in search, $ilike and $sw literally - #1176
Open
ravitejas-tech wants to merge 1 commit into
Open
ravitejas-tech wants to merge 1 commit into
ravitejas-tech wants to merge 1 commit into
Conversation
The search term and the $ilike and $sw filter values were put into LIKE patterns as they were, so `%` and `_` acted as wildcards: searching for `%` matched every row and `$sw:a_` matched `axb`. Escape `%`, `_` and the escape character in the term and add an ESCAPE '!' clause to the condition. `!` needs no quoting in SQL string literals, so the same clause works on Postgres, MySQL/MariaDB and SQLite, which has no default LIKE escape character. Fixes ppetzold#1175
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.
Fixes #1175
search,$ilikeand$swput the term into a LIKE pattern as it was, so%and_acted as wildcards: searching for%matched every row, and$sw:a_matchedaxb.The term is now escaped (
%,_and the escape character) and the LIKE condition gets anESCAPE '!'clause, also insideNOT(...)for$not:$ilike. I used!rather than\because it needs no quoting in SQL string literals, so the same clause works on Postgres, MySQL/MariaDB and SQLite, which has no default LIKE escape character. A backslash would need'\\'on MySQL/MariaDB and'\'everywhere else.This changes behaviour for anyone who passed
%or_through these operators on purpose: they now match literally.The new tests add a row named
50%_off!and coversearch(default andmultiWordSearch),$ilike,$swand$not:$ilike. The full suite passes locally on Postgres, MariaDB and SQLite.