dialect/sql: escape EqualFold on Postgres (#2860)

* adds tests for equalFold predicates

* ensure EqualFold escapes the argument on Postgres

* adds tests on builder as well
This commit is contained in:
Pedro Henrique
2022-08-16 04:09:06 -03:00
committed by GitHub
parent 4d11fe3383
commit 2b54aadcce
3 changed files with 24 additions and 1 deletions

View File

@@ -1703,14 +1703,17 @@ func (p *Predicate) EqualFold(col, sub string) *Predicate {
// We assume the CHARACTER SET is configured to utf8mb4,
// because this how it is defined in dialect/sql/schema.
b.Ident(col).WriteString(" COLLATE utf8mb4_general_ci = ")
b.Arg(strings.ToLower(sub))
case dialect.Postgres:
b.Ident(col).WriteString(" ILIKE ")
w, _ := escape(sub)
b.Arg(strings.ToLower(w))
default: // SQLite.
f.Lower(col)
b.WriteString(f.String())
b.WriteOp(OpEQ)
b.Arg(strings.ToLower(sub))
}
b.Arg(strings.ToLower(sub))
})
}