Skip to content

Commit

Permalink
fix: empty link bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ludusrusso committed Jun 24, 2024
1 parent 1ac1425 commit e122ea7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/mailbuilder/mailbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func insertTrackLinkInHTML(html string, link string) string {
return strings.Replace(html, "</body>", fmt.Sprintf(`<img src="%s" style="display:none;"/></body>`, link), 1)
}

var regLink = regexp.MustCompile(`<a\s+(?:[^>]*?\s+)?href=["'](.*?)["']`)
var regLink = regexp.MustCompile(`<a\s+(?:[^>]*?\s+)?href=["'](.+?)["']`)

func replaceLinks(html string, replace func(link string) (string, error)) (string, error) {
matches := regLink.FindAllStringSubmatch(html, -1)
Expand Down
16 changes: 16 additions & 0 deletions internal/mailbuilder/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ func TestInsertTrackLink(t *testing.T) {
assert.Equal(t, expectedhtml, res)
}

func TestEmptyAHrefLink(t *testing.T) {
html := `<html>
<body>
<a href="" />
</body></html>`

expectedhtml := html

res, err := replaceLinks(html, func(link string) (string, error) {
return link + "x", nil
})

assert.Nil(t, err)
assert.Equal(t, expectedhtml, res)
}

func TestReplaceCustomFields(t *testing.T) {
str := "Hello {{name}}"
fields := map[string]string{
Expand Down

0 comments on commit e122ea7

Please sign in to comment.