From f223f17c7645ebe6fac14842a5db750df0ce52ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 3 Mar 2016 19:45:23 +0100 Subject: [PATCH] tpl: Make chomp return template.HTML --- tpl/template_funcs.go | 4 ++-- tpl/template_funcs_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go index ba6349298..e74fc7d26 100644 --- a/tpl/template_funcs.go +++ b/tpl/template_funcs.go @@ -1196,13 +1196,13 @@ func relRef(page interface{}, ref string) template.HTML { } // chomp removes trailing newline characters from a string. -func chomp(text interface{}) (string, error) { +func chomp(text interface{}) (template.HTML, error) { s, err := cast.ToStringE(text) if err != nil { return "", err } - return strings.TrimRight(s, "\r\n"), nil + return template.HTML(strings.TrimRight(s, "\r\n")), nil } // trim leading/trailing characters defined by b from a diff --git a/tpl/template_funcs_test.go b/tpl/template_funcs_test.go index 4f277bedb..433d23b5f 100644 --- a/tpl/template_funcs_test.go +++ b/tpl/template_funcs_test.go @@ -63,10 +63,9 @@ func TestFuncsInTemplate(t *testing.T) { defer viper.Reset() // Add the examples from the docs: As a smoke test and to make sure the examples work. - // TODO(bep): Look at the use of safeHTML below; these should maybe return template.HTML // TODO(bep): docs: fix title example in := - `chomp: {{chomp "

Blockhead

\n" | safeHTML }} + `chomp: {{chomp "

Blockhead

\n" }} dateFormat: {{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }} lower: {{lower "BatMan"}} markdownify: {{ .Title | markdownify}} @@ -1643,7 +1642,8 @@ func TestChomp(t *testing.T) { "\r", "\r\r", "\r\n", "\r\n\r\n", } { - chomped, _ := chomp(base + item) + c, _ := chomp(base + item) + chomped := string(c) if chomped != base { t.Errorf("[%d] Chomp failed, got '%v'", i, chomped)