feat(subsonic): replace html2text with bluemonday

fixes #591

Release-As: 0.17.1
This commit is contained in:
sentriz
2025-08-26 00:53:33 +01:00
parent 72376a4568
commit 5916a7fe7b
3 changed files with 15 additions and 22 deletions

No files matched your search

+6 -2
View File
@@ -2,14 +2,15 @@ package spec
import (
"fmt"
"html"
"regexp"
"strings"
"time"
"unicode"
"github.com/microcosm-cc/bluemonday"
"go.senan.xyz/gonic"
"go.senan.xyz/gonic/server/ctrlsubsonic/specid"
"jaytaylor.com/html2text"
)
// https://web.archive.org/web/20220707025402/https://www.subsonic.org/pages/api.jsp
@@ -515,8 +516,11 @@ var doublePuncExpr = regexp.MustCompile(`\.\s+\.\s+`)
var licenceExpr = regexp.MustCompile(`(?i)\buser-contributed text.*`)
var readMoreExpr = regexp.MustCompile(`(?i)\bread more on.*`)
var bluemondayPolicy = bluemonday.StrictPolicy() //nolint:gochecknoglobals
func CleanExternalText(text string) string {
text, _ = html2text.FromString(text, html2text.Options{TextOnly: true})
text = bluemondayPolicy.Sanitize(text)
text = html.UnescapeString(text)
text = licenceExpr.ReplaceAllString(text, "")
text = readMoreExpr.ReplaceAllString(text, "")
text = doublePuncExpr.ReplaceAllString(text, ". ")