From 1fdce9dada8262ccca890a93a56556fc4262be43 Mon Sep 17 00:00:00 2001 From: Wheeler Law Date: Wed, 15 Aug 2018 22:48:20 -0400 Subject: [PATCH] Tests are passing --- template/interpolate/funcs.go | 10 +++++++++- template/interpolate/funcs_test.go | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) 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`, },