diff options
author | 2023-08-11 14:40:11 +0200 | |
---|---|---|
committer | 2023-08-11 14:40:11 +0200 | |
commit | dc96562b4084e058846aea9102ef0257461717d6 (patch) | |
tree | a0b4bdbaa266386c7fdbbc02ca3e62bae559bf17 /internal/text/minify.go | |
parent | [feature] Set Content-Security-Policy header (#2095) (diff) | |
download | gotosocial-dc96562b4084e058846aea9102ef0257461717d6.tar.xz |
[bugfix] Use custom bluemonday policy to disallow inline img tags (#2100)
Diffstat (limited to 'internal/text/minify.go')
-rw-r--r-- | internal/text/minify.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/text/minify.go b/internal/text/minify.go index 83780d5c1..da61bdcf9 100644 --- a/internal/text/minify.go +++ b/internal/text/minify.go @@ -18,6 +18,7 @@ package text import ( + "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/tdewolff/minify/v2" "github.com/tdewolff/minify/v2/html" ) @@ -31,3 +32,23 @@ var m = func() *minify.M { }) return m }() + +// MinifyHTML minifies the given string +// under the assumption that it's HTML. +// +// If input is not HTML encoded, this +// function will try to do minimization +// anyway, but this may produce unexpected +// results. +// +// If an error occurs during minimization, +// it will be logged and the original string +// returned unmodified. +func MinifyHTML(in string) string { + out, err := m.String("text/html", in) + if err != nil { + log.Error(nil, err) + } + + return out +} |