Skip to content

Commit

Permalink
Ensure that LIKE pattern does not get converted by field converter.
Browse files Browse the repository at this point in the history
Fixes #2609
  • Loading branch information
coleifer committed Aug 26, 2022
1 parent b36aea9 commit 4e12d7f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion peewee.py
Expand Up @@ -1204,7 +1204,13 @@ def is_null(self, is_null=True):
def _escape_like_expr(self, s, template):
if s.find('_') >= 0 or s.find('%') >= 0 or s.find('\\') >= 0:
s = s.replace('\\', '\\\\').replace('_', '\\_').replace('%', '\\%')
return NodeList((template % s, SQL('ESCAPE'), '\\'))
# Pass the expression and escape string as unconverted values, to
# avoid (e.g.) a Json field converter turning the escaped LIKE
# pattern into a Json-quoted string.
return NodeList((
Value(template % s, converter=False),
SQL('ESCAPE'),
Value('\\', converter=False)))
return template % s
def contains(self, rhs):
if isinstance(rhs, Node):
Expand Down

0 comments on commit 4e12d7f

Please sign in to comment.