From 8d91ee8ac7a161ad602cfcd678c4bdcf1678eacc Mon Sep 17 00:00:00 2001 From: dogukanakkaya Date: Sat, 4 Oct 2025 17:34:38 +0300 Subject: [PATCH] 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 {