Support for Windows newlines.
This commit is contained in:
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…
Reference in New Issue