~netlandish/links-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH links] Fixing bug when no valid input is given to the tsquery conversion.

Details
Message ID
<20250320141342.17989-1-peter@netlandish.com>
Sender timestamp
1742458418
DKIM signature
missing
Download raw message
Patch: +14 -11
Fixed: ISE when no valid input is given to a query used in tsquery
  conversions.
Signed-off-by: Peter Sanchez <peter@netlandish.com>
---
 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.47.2
Details
Message ID
<D8L5O6604RIC.1JEM07U0HACVE@netlandish.com>
In-Reply-To
<20250320141342.17989-1-peter@netlandish.com> (view parent)
Sender timestamp
1742458576
DKIM signature
missing
Download raw message
Applied.

To git@git.code.netlandish.com:~netlandish/links
   3c4d9f9..536b6d2  master -> master
Reply to thread Export thread (mbox)