fix: limit redirect count when parsing html for favicon, fix url sanitize method

This commit is contained in:
yusing
2025-03-29 09:35:12 +08:00
parent d2e2086540
commit 146e7781be
2 changed files with 18 additions and 6 deletions

View File

@@ -1,6 +1,9 @@
package strutils
import "path"
import (
"path"
"strings"
)
// SanitizeURI sanitizes a URI reference to ensure it is safe
// It disallows URLs beginning with // or /\ as absolute URLs,
@@ -10,6 +13,9 @@ func SanitizeURI(uri string) string {
if uri == "" {
return "/"
}
if strings.HasPrefix(uri, "http://") || strings.HasPrefix(uri, "https://") {
return uri
}
if uri[0] != '/' {
uri = "/" + uri
}