diff --git a/template/interpolate/funcs.go b/template/interpolate/funcs.go index 03b9a8351..5b67e5afb 100644 --- a/template/interpolate/funcs.go +++ b/template/interpolate/funcs.go @@ -257,7 +257,7 @@ func funcGenVault(ctx *Context) interface{} { } func funcGenSed(ctx *Context) interface{} { - return func(inputString string, expression string) (string, error) { + return func(expression string, inputString string) (string, error) { engine, err := sed.New(strings.NewReader(expression)) if err != nil { @@ -266,6 +266,14 @@ func funcGenSed(ctx *Context) interface{} { result, err := engine.RunString(inputString) + if err != nil{ + return "", err + } + + // The sed library adds a \n to all processed strings. + resultLength := len(result) + result = result[:resultLength-1] + return result, err } } diff --git a/template/interpolate/funcs_test.go b/template/interpolate/funcs_test.go index 99e14bd49..b624a160f 100644 --- a/template/interpolate/funcs_test.go +++ b/template/interpolate/funcs_test.go @@ -322,12 +322,12 @@ func TestFuncSed(t *testing.T) { Output string }{ { - `{{sed "hello" "s|hello|world|"}}`, + `{{sed "s|hello|world|" "hello"}}`, `world`, }, { - `{{sed "hello" "s|foo|bar|"}}`, + `{{sed "s|foo|bar|" "hello"}}`, `hello`, },