1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-06 17:41:00 +00:00

perf(sanitizer): improve the performances of the sanitizer (#3497)

- Grow the underlying buffer of SanitizeHTML's strings.Builder to 3/4 of the
  raw HTML from the start, to reduce the amount of iterative allocations. This
  number is a complete guesstimation, but it sounds reasonable to me.
- Add a `absoluteURLParsedBase` function to avoid parsing baseURL over and over.
This commit is contained in:
Julien Voisin 2025-07-08 00:21:13 +02:00 committed by GitHub
parent 15e4c3a374
commit a8b4e88742
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 15 deletions

View file

@ -18,22 +18,34 @@ func IsAbsoluteURL(link string) bool {
return u.IsAbs()
}
// AbsoluteURL converts the input URL as absolute URL if necessary.
func AbsoluteURL(baseURL, input string) (string, error) {
// GetAbsoluteURL return the absolute form of `input` is possible, as well as its parser form.
func GetAbsoluteURL(input string) (string, *url.URL, error) {
if strings.HasPrefix(input, "//") {
return "https:" + input, nil
return "https:" + input, nil, nil
}
if strings.HasPrefix(input, "https://") || strings.HasPrefix(input, "http://") {
return input, nil
return input, nil, nil
}
u, err := url.Parse(input)
if err != nil {
return "", fmt.Errorf("unable to parse input URL: %v", err)
return "", nil, fmt.Errorf("unable to parse input URL: %v", err)
}
if u.IsAbs() {
return u.String(), nil
return u.String(), u, nil
}
return "", u, nil
}
// AbsoluteURL converts the input URL as absolute URL if necessary.
func AbsoluteURL(baseURL, input string) (string, error) {
absURL, u, err := GetAbsoluteURL(input)
if err != nil {
return "", err
}
if absURL != "" {
return absURL, nil
}
base, err := url.Parse(baseURL)