From 3cad9177de80bb04e6cd0f4b36f45877a2cafe0a Mon Sep 17 00:00:00 2001 From: Nikita Tokarchuk Date: Wed, 2 Feb 2022 22:46:29 +0100 Subject: [PATCH 1/2] Trim path ending separators --- pkg/routes/index.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/routes/index.go b/pkg/routes/index.go index ffeabea..e853239 100644 --- a/pkg/routes/index.go +++ b/pkg/routes/index.go @@ -38,6 +38,15 @@ func (r *Routes) usePostfixForce(c *routing.Context) (err error) { return c.Next() } + fullPath = bytes.TrimRightFunc(fullPath, func(r rune) bool { + switch r { + case '/': + return true + default: + return false + } + }) + fullPath = append(fullPath, '.') fullPath = append(fullPath, []byte(templates.URLPostfix)...) From a5b021e3df8106bcf685c948b3c178b978d5aaaf Mon Sep 17 00:00:00 2001 From: Nikita Tokarchuk Date: Wed, 2 Feb 2022 22:46:57 +0100 Subject: [PATCH 2/2] Keep query args when postfix append --- pkg/routes/index.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/routes/index.go b/pkg/routes/index.go index e853239..cf7c41c 100644 --- a/pkg/routes/index.go +++ b/pkg/routes/index.go @@ -49,6 +49,7 @@ func (r *Routes) usePostfixForce(c *routing.Context) (err error) { fullPath = append(fullPath, '.') fullPath = append(fullPath, []byte(templates.URLPostfix)...) + fullPath = c.QueryArgs().AppendBytes(fullPath) return r.relativeRedirectBytes(c, fullPath, fasthttp.StatusFound) }