Problem: MatchString is used in a loop

Solution: Compile regex outside loop
This commit is contained in:
Peter Stuifzand 2021-11-20 21:15:17 +01:00
parent e98d9545d0
commit 67bc36bb66
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -89,6 +89,11 @@ func simplifyContent(k string, v []interface{}) *microsub.Content {
func CleanHTML(s string) (string, error) { func CleanHTML(s string) (string, error) {
doc, err := html.Parse(strings.NewReader(s)) doc, err := html.Parse(strings.NewReader(s))
whitespaceRegex, err := regexp.Compile(`white-space:\s*pre`)
if err != nil {
return "", err
}
if err != nil { if err != nil {
return "", err return "", err
} }
@ -101,7 +106,7 @@ func CleanHTML(s string) (string, error) {
if a.Key != "style" { if a.Key != "style" {
continue continue
} }
if m, err := regexp.MatchString("white-space:\\s*pre", a.Val); err == nil && m { if whitespaceRegex.MatchString(a.Val) {
removeIndex = i removeIndex = i
break break
} }