diff --git a/internal/mailbuilder/mailbuilder.go b/internal/mailbuilder/mailbuilder.go index 51e8632..2785cf6 100644 --- a/internal/mailbuilder/mailbuilder.go +++ b/internal/mailbuilder/mailbuilder.go @@ -186,7 +186,7 @@ func insertTrackLinkInHTML(html string, link string) string { return strings.Replace(html, "", fmt.Sprintf(``, link), 1) } -var regLink = regexp.MustCompile(`]*?\s+)?href=["'](.*?)["']`) +var regLink = regexp.MustCompile(`]*?\s+)?href=["'](.+?)["']`) func replaceLinks(html string, replace func(link string) (string, error)) (string, error) { matches := regLink.FindAllStringSubmatch(html, -1) diff --git a/internal/mailbuilder/message_test.go b/internal/mailbuilder/message_test.go index 342a18e..a7eac3c 100644 --- a/internal/mailbuilder/message_test.go +++ b/internal/mailbuilder/message_test.go @@ -82,6 +82,22 @@ func TestInsertTrackLink(t *testing.T) { assert.Equal(t, expectedhtml, res) } +func TestEmptyAHrefLink(t *testing.T) { + 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{