fix: correctly escape backslash in queries (#10522)

# Which Problems Are Solved

While investigating a support ticket, it was discovered that some
queries using equals or not equals without case matching were not
correctly escaping the value to compare. If a value contained a
backslash (`\`) the row would not match.

# How the Problems Are Solved

- Fixed the escaping for backslash for `like` operations.
- Changed equals and not equals comparison without case matching to `=`
instead of `like`.

# Additional Changes

None

# Additional Context

- related to a support request
- requires backport to v.3 and v4.x
This commit is contained in:
Livio Spring
2025-08-21 07:25:23 +02:00
committed by GitHub
parent a28950661c
commit 6c8d027e72
3 changed files with 26 additions and 14 deletions

View File

@@ -288,9 +288,7 @@ func NewTextQuery(col Column, value string, compare TextComparison) (*textQuery,
}
// handle the comparisons which use (i)like and therefore need to escape potential wildcards in the value
switch compare {
case TextEqualsIgnoreCase,
TextNotEqualsIgnoreCase,
TextStartsWith,
case TextStartsWith,
TextStartsWithIgnoreCase,
TextEndsWith,
TextEndsWithIgnoreCase,
@@ -300,6 +298,8 @@ func NewTextQuery(col Column, value string, compare TextComparison) (*textQuery,
case TextEquals,
TextListContains,
TextNotEquals,
TextEqualsIgnoreCase,
TextNotEqualsIgnoreCase,
textCompareMax:
// do nothing
}
@@ -335,9 +335,9 @@ func (q *textQuery) comp() sq.Sqlizer {
case TextNotEquals:
return sq.NotEq{q.Column.identifier(): q.Text}
case TextEqualsIgnoreCase:
return sq.Like{"LOWER(" + q.Column.identifier() + ")": strings.ToLower(q.Text)}
return sq.Eq{"LOWER(" + q.Column.identifier() + ")": strings.ToLower(q.Text)}
case TextNotEqualsIgnoreCase:
return sq.NotLike{"LOWER(" + q.Column.identifier() + ")": strings.ToLower(q.Text)}
return sq.NotEq{"LOWER(" + q.Column.identifier() + ")": strings.ToLower(q.Text)}
case TextStartsWith:
return sq.Like{q.Column.identifier(): q.Text + "%"}
case TextStartsWithIgnoreCase: