fix(query): escape wildcards in text search (#7131) (#7135)

* fix(query): escape like wildcards

* test: search query wildcards

* add do nothing
This commit is contained in:
Silvan
2024-01-02 16:27:36 +01:00
committed by GitHub
parent 9892fd92b6
commit 8bc56f6fe7
6 changed files with 736 additions and 51 deletions

View File

@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"reflect"
"strings"
"github.com/mitchellh/mapstructure"
"github.com/zitadel/logging"
@@ -84,6 +85,7 @@ func (db *DB) QueryRowContext(ctx context.Context, scan func(row *sql.Row) error
}()
row := tx.QueryRowContext(ctx, query, args...)
logging.OnError(row.Err()).Error("unexpected query error")
err = scan(row)
if err != nil {
@@ -170,3 +172,9 @@ func (c Config) Password() string {
func (c Config) Type() string {
return c.connector.Type()
}
func EscapeLikeWildcards(value string) string {
value = strings.ReplaceAll(value, "%", "\\%")
value = strings.ReplaceAll(value, "_", "\\_")
return value
}