From 8d91ee8ac7a161ad602cfcd678c4bdcf1678eacc Mon Sep 17 00:00:00 2001 From: dogukanakkaya Date: Sat, 4 Oct 2025 17:34:38 +0300 Subject: [PATCH 1/2] feat(templatemailer): getPath function should append existing query strings instead of overwrite --- internal/mailer/templatemailer/templatemailer.go | 6 ++++++ internal/mailer/templatemailer/templatemailer_url_test.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/internal/mailer/templatemailer/templatemailer.go b/internal/mailer/templatemailer/templatemailer.go index 05726baad..f1c2f2b56 100644 --- a/internal/mailer/templatemailer/templatemailer.go +++ b/internal/mailer/templatemailer/templatemailer.go @@ -465,6 +465,12 @@ func getPath(filepath string, params *emailParams) (*url.URL, error) { } if params != nil { path.RawQuery = fmt.Sprintf("token=%s&type=%s&redirect_to=%s", url.QueryEscape(params.Token), url.QueryEscape(params.Type), encodeRedirectURL(params.RedirectTo)) + + // If the path already has query params, append them + q := path.Query().Encode() + if q != "" { + path.RawQuery += fmt.Sprintf("&%s", q) + } } return path, nil } diff --git a/internal/mailer/templatemailer/templatemailer_url_test.go b/internal/mailer/templatemailer/templatemailer_url_test.go index 672d37130..074013cb1 100644 --- a/internal/mailer/templatemailer/templatemailer_url_test.go +++ b/internal/mailer/templatemailer/templatemailer_url_test.go @@ -56,6 +56,12 @@ func TestGetPath(t *testing.T) { Params: ¶ms, Expected: "https://test.example.com?token=token&type=signup&redirect_to=https://example.com", }, + { + SiteURL: "https://test.example.com/", + Path: "/trailingslash?flow=test", + Params: ¶ms, + Expected: "https://test.example.com/trailingslash?token=token&type=signup&redirect_to=https://example.com&flow=test", + }, } for _, c := range cases { From ad456174e6541593c6eb9e0ebd721d1e8702ac4b Mon Sep 17 00:00:00 2001 From: dogukanakkaya Date: Wed, 29 Oct 2025 17:41:55 +0300 Subject: [PATCH 2/2] refactor: append existing query params (raw) --- internal/mailer/templatemailer/templatemailer.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/mailer/templatemailer/templatemailer.go b/internal/mailer/templatemailer/templatemailer.go index 5dcf091a7..3f5771c3f 100644 --- a/internal/mailer/templatemailer/templatemailer.go +++ b/internal/mailer/templatemailer/templatemailer.go @@ -502,12 +502,13 @@ func getPath(filepath string, params *emailParams) (*url.URL, error) { } } if params != nil { - path.RawQuery = fmt.Sprintf("token=%s&type=%s&redirect_to=%s", url.QueryEscape(params.Token), url.QueryEscape(params.Type), encodeRedirectURL(params.RedirectTo)) + baseQuery := fmt.Sprintf("token=%s&type=%s&redirect_to=%s", url.QueryEscape(params.Token), url.QueryEscape(params.Type), encodeRedirectURL(params.RedirectTo)) - // If the path already has query params, append them - q := path.Query().Encode() - if q != "" { - path.RawQuery += fmt.Sprintf("&%s", q) + // Append existing query params if any + if existing := path.RawQuery; existing != "" { + path.RawQuery = fmt.Sprintf("%s&%s", baseQuery, existing) + } else { + path.RawQuery = baseQuery } } return path, nil