From 536b6d2fce8fd0a38bd9cabda665901bdbaff6d5 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Thu, 20 Mar 2025 08:13:38 -0600 Subject: [PATCH] Fixing bug when no valid input is given to the tsquery conversion. Fixed: ISE when no valid input is given to a query used in tsquery conversions. Signed-off-by: Peter Sanchez --- core/routes.go | 11 ++++++----- helpers.go | 12 +++++++----- migrations/0006_update_auditlog_metadata.down.sql | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/routes.go b/core/routes.go index 661c1d9..5d2995b 100644 --- a/core/routes.go +++ b/core/routes.go @@ -3187,13 +3187,14 @@ func (s *Service) TagAutocomplete(c echo.Context) error { gctx := c.(*server.Context) user := gctx.User.(*models.User) orgID := c.QueryParam("org") - q := c.QueryParam("q") - var tags []*models.Tag - var err error + q := links.ParseSearch(c.QueryParam("q")) + var ( + tags []*models.Tag + err error + ) if q != "" { - s := links.ParseSearch(q) opts := &database.FilterOptions{ - Filter: sq.Expr(`to_tsvector('simple', t.name) @@ to_tsquery('simple', ?)`, s), + Filter: sq.Expr(`to_tsvector('simple', t.name) @@ to_tsquery('simple', ?)`, q), } if orgID != "" { opts.Filter = sq.And{ diff --git a/helpers.go b/helpers.go index e1da322..9f86203 100644 --- a/helpers.go +++ b/helpers.go @@ -864,12 +864,14 @@ func ParseSearch(s string) string { var words []string for _, word := range strings.Split(s, " ") { // This is used for to_tsquery searches (tag autocomplete) - word = strings.TrimSpace(word) - word = strings.Replace(word, ":", "\\:", -1) - if !strings.HasPrefix(word, "-") { - word = word + ":*" + if len(word) > 0 { + word = strings.TrimSpace(word) + word = strings.Replace(word, ":", "\\:", -1) + if !strings.HasPrefix(word, "-") { + word = word + ":*" + } + words = append(words, word) } - words = append(words, word) } s = strings.Join(words, " & ") return s diff --git a/migrations/0006_update_auditlog_metadata.down.sql b/migrations/0006_update_auditlog_metadata.down.sql index 5297243..da8c679 100644 --- a/migrations/0006_update_auditlog_metadata.down.sql +++ b/migrations/0006_update_auditlog_metadata.down.sql @@ -1,3 +1,3 @@ UPDATE audit_log SET metadata = metadata - 'org_slug' WHERE metadata ? 'org_slug'; UPDATE audit_log SET metadata = metadata - 'list_slug' WHERE metadata ? 'list_slug'; -DROP INDEX audit_log_metadata_gin; +DROP INDEX IF EXISTS audit_log_metadata_gin; -- 2.45.3