From 6ca0978777bd8e796376162520fc3ea561b644c8 Mon Sep 17 00:00:00 2001 From: "Iskander (Alex) Sharipov" Date: Sat, 26 Jan 2019 14:13:53 +0300 Subject: [PATCH] replace unchecked Compile calls with MustCompile For constant patterns and especially when errors are ignored, `regexp.MustCompile` is a better choice than `regexp.Compile`. Signed-off-by: Iskander Sharipov --- templatefunc.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templatefunc.go b/templatefunc.go index 9ec2a9e8..7a8d5588 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -55,21 +55,21 @@ func Substr(s string, start, length int) string { // HTML2str returns escaping text convert from html. func HTML2str(html string) string { - re, _ := regexp.Compile(`\<[\S\s]+?\>`) + re := regexp.MustCompile(`\<[\S\s]+?\>`) html = re.ReplaceAllStringFunc(html, strings.ToLower) //remove STYLE - re, _ = regexp.Compile(`\`) + re = regexp.MustCompile(`\`) html = re.ReplaceAllString(html, "") //remove SCRIPT - re, _ = regexp.Compile(`\`) + re = regexp.MustCompile(`\`) html = re.ReplaceAllString(html, "") - re, _ = regexp.Compile(`\<[\S\s]+?\>`) + re = regexp.MustCompile(`\<[\S\s]+?\>`) html = re.ReplaceAllString(html, "\n") - re, _ = regexp.Compile(`\s{2,}`) + re = regexp.MustCompile(`\s{2,}`) html = re.ReplaceAllString(html, "\n") return strings.TrimSpace(html)