Fix quotes issue in TrackLink regexp.

This commit is contained in:
Kailash Nadh 2025-05-25 15:13:51 +05:30
parent 70fe7cba6f
commit dc466fc76b

View file

@ -98,11 +98,11 @@ type regTplFunc struct {
var regTplFuncs = []regTplFunc{
// Regular expression for matching {{ TrackLink "http://link.com" }} in the template
// and substituting it with {{ Track "http://link.com" . }} (the dot context)
// and substituting it with {{ TrackLink "http://link.com" . }} (the dot context)
// before compilation. This is to make linking easier for users.
{
regExp: regexp.MustCompile(`{{(\s+)?TrackLink(\s+)?(.+?)(\s+)?}}`),
replace: `{{ TrackLink $3 . }}`,
regExp: regexp.MustCompile(`{{\s*TrackLink\s+"([^"]+)"\s*}}`),
replace: `{{ TrackLink "$1" . }}`,
},
// Convert the shorthand https://google.com@TrackLink to {{ TrackLink ... }}.
@ -543,6 +543,7 @@ func (c *Campaign) CompileTemplate(f template.FuncMap) error {
for _, r := range regTplFuncs {
body = r.regExp.ReplaceAllString(body, r.replace)
}
baseTPL, err := template.New(BaseTpl).Funcs(f).Parse(body)
if err != nil {
return fmt.Errorf("error compiling base template: %v", err)