From 8d2e62f6687f5ca507bc9b18f97d06b50313a1bb Mon Sep 17 00:00:00 2001 From: Yader Velasquez Date: Thu, 15 Feb 2024 16:52:56 -0600 Subject: [PATCH] Fix bug in AddQueryElement func. Avoid appending new query params to previous url.Values. References: https://todo.code.netlandish.com/~netlandish/links/47 --- core/routes.go | 3 ++- helpers.go | 12 ++++++++---- list/routes.go | 2 +- short/routes.go | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/core/routes.go b/core/routes.go index df75ba6..6c5e28b 100644 --- a/core/routes.go +++ b/core/routes.go @@ -4,6 +4,7 @@ import ( "database/sql" "errors" "fmt" + "html/template" "links" "links/analytics" "links/domain" @@ -1443,7 +1444,7 @@ func (s *Service) OrgLinksList(c echo.Context) error { "hasStarredFilter": hasStarredFilter, "hasAllFilter": hasAllFilter, "currURL": currURL, - "queries": queries, + "queries": template.URL(queries.Encode()), } if search != "" { diff --git a/helpers.go b/helpers.go index ee129cc..992d1d6 100644 --- a/helpers.go +++ b/helpers.go @@ -757,15 +757,19 @@ func (t TagQuery) GetSubQuery(inputTag, inputExcludeTag *string) (string, []inte return subQ.ToSql() } -func AddQueryElement(q url.Values, param, val string) template.URL { - curVal := q.Get(param) +func AddQueryElement(q template.URL, param, val string) template.URL { + query, err := url.ParseQuery(string(q)) + if err != nil { + return "" + } + curVal := query.Get(param) if curVal == "" { curVal = val } else { curVal += fmt.Sprintf(",%s", val) } - q.Set(param, curVal) - return template.URL(q.Encode()) + query.Set(param, curVal) + return template.URL(query.Encode()) } // GetLinksDomain will simply return the config value for `links:links-service-domain` diff --git a/list/routes.go b/list/routes.go index 1f68806..646d051 100644 --- a/list/routes.go +++ b/list/routes.go @@ -1068,7 +1068,7 @@ func (s *Service) ListingList(c echo.Context) error { "tagFilter": strings.Replace(tag, ",", ", ", -1), "excludeTagFilter": strings.Replace(excludeTag, ",", ", ", -1), "advancedSearch": true, - "queries": queries, + "queries": template.URL(queries.Encode()), } if result.Listings.PageInfo.HasPrevPage { gmap["prevURL"] = links.GetPaginationParams("prev", tag, "", result.Listings.PageInfo.Cursor) diff --git a/short/routes.go b/short/routes.go index 88cf64c..0bd22d3 100644 --- a/short/routes.go +++ b/short/routes.go @@ -3,6 +3,7 @@ package short import ( "errors" "fmt" + "html/template" "links" "links/analytics" "links/domain" @@ -175,7 +176,7 @@ func (s *Service) LinkShortList(c echo.Context) error { "tagFilter": strings.Replace(tag, ",", ", ", -1), "excludeTagFilter": strings.Replace(excludeTag, ",", ", ", -1), "advancedSearch": true, - "queries": queries, + "queries": template.URL(queries.Encode()), } if result.LinkShorts.PageInfo.HasPrevPage { -- 2.45.2