diff --git a/template/template.go b/template/template.go index 7056a13a8..27f7067a7 100644 --- a/template/template.go +++ b/template/template.go @@ -31,7 +31,7 @@ var substitutionNamed = "[_a-z][_a-z0-9]*" var substitutionBraced = "[_a-z][_a-z0-9]*(?::?[-+?](.*}|[^}]*))?" var patternString = fmt.Sprintf( - "%s(?i:(?P%s)|(?P%s)|{(?P%s)}|(?P))", + "%s(?i:(?P%s)|(?P%s)|{(?:(?P%s)}|(?P)))", delimiter, delimiter, substitutionNamed, substitutionBraced, ) diff --git a/template/template_test.go b/template/template_test.go index a2a044410..27c0f0e4a 100644 --- a/template/template_test.go +++ b/template/template_test.go @@ -47,10 +47,24 @@ func TestSubstituteNoMatch(t *testing.T) { assert.Equal(t, "foo", result) } +func TestUnescaped(t *testing.T) { + templates := []string{ + "a $ string", + "^REGEX$", + "$}", + "$", + } + + for _, expected := range templates { + actual, err := Substitute(expected, defaultMapping) + assert.NilError(t, err) + assert.Equal(t, expected, actual) + } +} + func TestInvalid(t *testing.T) { invalidTemplates := []string{ "${", - "$}", "${}", "${ }", "${ foo}",