mirror of
https://github.com/miniflux/v2.git
synced 2025-07-02 16:38:37 +00:00
refactor(sanitizer): optimize internal/reader/sanitizer/strip_tags.go
- Use strings instead of doing string->bytes->string - Use a strings.Builder to build the output
This commit is contained in:
parent
331c831c23
commit
bfb429b919
1 changed files with 3 additions and 3 deletions
|
@ -4,8 +4,8 @@
|
||||||
package sanitizer // import "miniflux.app/v2/internal/reader/sanitizer"
|
package sanitizer // import "miniflux.app/v2/internal/reader/sanitizer"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/net/html"
|
"golang.org/x/net/html"
|
||||||
)
|
)
|
||||||
|
@ -13,8 +13,8 @@ import (
|
||||||
// StripTags removes all HTML/XML tags from the input string.
|
// StripTags removes all HTML/XML tags from the input string.
|
||||||
// This function must *only* be used for cosmetic purposes, not to prevent code injections like XSS.
|
// This function must *only* be used for cosmetic purposes, not to prevent code injections like XSS.
|
||||||
func StripTags(input string) string {
|
func StripTags(input string) string {
|
||||||
tokenizer := html.NewTokenizer(bytes.NewBufferString(input))
|
tokenizer := html.NewTokenizer(strings.NewReader(input))
|
||||||
var buffer bytes.Buffer
|
var buffer strings.Builder
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if tokenizer.Next() == html.ErrorToken {
|
if tokenizer.Next() == html.ErrorToken {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue