mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Replace regexp based Chomp with builtin TrimRight
This commit is contained in:
@@ -29,7 +29,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -38,7 +37,6 @@ import (
|
||||
var localTemplates *template.Template
|
||||
var tmpl Template
|
||||
var funcMap template.FuncMap
|
||||
var chompRegexp *regexp.Regexp
|
||||
|
||||
type Template interface {
|
||||
ExecuteTemplate(wr io.Writer, name string, data interface{}) error
|
||||
@@ -877,7 +875,7 @@ func Chomp(text interface{}) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return chompRegexp.ReplaceAllString(s, ""), nil
|
||||
return strings.TrimRight(s, "\r\n"), nil
|
||||
}
|
||||
|
||||
// Trim leading/trailing characters defined by b from a
|
||||
@@ -1284,5 +1282,4 @@ func init() {
|
||||
"trim": Trim,
|
||||
}
|
||||
|
||||
chompRegexp = regexp.MustCompile("[\r\n]+$")
|
||||
}
|
||||
|
@@ -835,9 +835,9 @@ func TestMarkdownify(t *testing.T) {
|
||||
func TestChomp(t *testing.T) {
|
||||
base := "\n This is\na story "
|
||||
for i, item := range []string{
|
||||
"\n",
|
||||
"\r",
|
||||
"\r\n",
|
||||
"\n", "\n\n",
|
||||
"\r", "\r\r",
|
||||
"\r\n", "\r\n\r\n",
|
||||
} {
|
||||
chomped, _ := Chomp(base + item)
|
||||
|
||||
|
Reference in New Issue
Block a user