Problem: MatchString is used in a loop
Solution: Compile regex outside loop
This commit is contained in:
parent
e98d9545d0
commit
67bc36bb66
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user