Support for Windows newlines.

pull/13419/head
Joern Barthel 9 years ago
parent 059a1b2c0f
commit 9622b49c45

@ -462,11 +462,12 @@ func interpolationFuncCeil() ast.Function {
// interpolationFuncChomp removes trailing newlines from the given string
func interpolationFuncChomp() ast.Function {
newlines := regexp.MustCompile(`(?:\r\n?|\n)*\z`)
return ast.Function{
ArgTypes: []ast.Type{ast.TypeString},
ReturnType: ast.TypeString,
Callback: func(args []interface{}) (interface{}, error) {
return strings.TrimRight(args[0].(string), "\n"), nil
return newlines.ReplaceAllString(args[0].(string), ""), nil
},
}
}

@ -386,10 +386,38 @@ func TestInterpolateFuncChomp(t *testing.T) {
},
{
`${chomp("goodbye\ncruel\nworld\n")}`,
`goodbye
cruel
world`,
fmt.Sprintf(`${chomp("%s")}`, "goodbye\ncruel\nworld"),
"goodbye\ncruel\nworld",
false,
},
{
fmt.Sprintf(`${chomp("%s")}`, "goodbye\r\nwindows\r\nworld"),
"goodbye\r\nwindows\r\nworld",
false,
},
{
fmt.Sprintf(`${chomp("%s")}`, "goodbye\ncruel\nworld\n"),
"goodbye\ncruel\nworld",
false,
},
{
fmt.Sprintf(`${chomp("%s")}`, "goodbye\ncruel\nworld\n\n\n\n"),
"goodbye\ncruel\nworld",
false,
},
{
fmt.Sprintf(`${chomp("%s")}`, "goodbye\r\nwindows\r\nworld\r\n"),
"goodbye\r\nwindows\r\nworld",
false,
},
{
fmt.Sprintf(`${chomp("%s")}`, "goodbye\r\nwindows\r\nworld\r\n\r\n\r\n\r\n"),
"goodbye\r\nwindows\r\nworld",
false,
},
},

Loading…
Cancel
Save