shithub: hugo

Download patch

ref: f223f17c7645ebe6fac14842a5db750df0ce52ba
parent: daaf4eb3306a89f81cf994071ec4c105d4d1edd0
author: Bjørn Erik Pedersen <[email protected]>
date: Thu Mar 3 14:45:23 EST 2016

tpl: Make chomp return template.HTML

--- a/tpl/template_funcs.go
+++ b/tpl/template_funcs.go
@@ -1196,13 +1196,13 @@
 }
 
 // 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
--- a/tpl/template_funcs_test.go
+++ b/tpl/template_funcs_test.go
@@ -63,10 +63,9 @@
 	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 "<p>Blockhead</p>\n" | safeHTML }}
+		`chomp: {{chomp "<p>Blockhead</p>\n" }}
 dateFormat: {{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }}
 lower: {{lower "BatMan"}}
 markdownify: {{ .Title | markdownify}}
@@ -1643,7 +1642,8 @@
 		"\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)