Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/mailer/templatemailer/templatemailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of string concatenation, this should build the query object instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default Go alphabetically sorts the query parameters which causes other tests to fail. Even if I change that, using .Encode() encodes the redirect_to=https%3A%2F%2Fexample.com&..., again this also fails. I either need to change the tests in order to be compatible with the code. Nonetheless, I'll refactor this part a bit.

If you want me to change the tests as well and use query builder I can do that also.

}
}
return path, nil
}
Expand Down
6 changes: 6 additions & 0 deletions internal/mailer/templatemailer/templatemailer_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func TestGetPath(t *testing.T) {
Params: &params,
Expected: "https://test.example.com?token=token&type=signup&redirect_to=https://example.com",
},
{
SiteURL: "https://test.example.com/",
Path: "/trailingslash?flow=test",
Params: &params,
Expected: "https://test.example.com/trailingslash?token=token&type=signup&redirect_to=https://example.com&flow=test",
},
}

for _, c := range cases {
Expand Down