From 902ca63c4509c3e1589470a6252266542ef41c7d Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 7 Dec 2024 23:00:42 +0100 Subject: [PATCH] Inline a function and fix a bug in it The `isAnchor` function's first parameter was always `a`, instead of being passed `tagName`. As this function is a single line and was only called in a single place, it can be inlined. --- internal/reader/sanitizer/sanitizer.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/internal/reader/sanitizer/sanitizer.go b/internal/reader/sanitizer/sanitizer.go index 21e95055..fe20f9a1 100644 --- a/internal/reader/sanitizer/sanitizer.go +++ b/internal/reader/sanitizer/sanitizer.go @@ -195,7 +195,7 @@ func sanitizeAttributes(baseURL, tagName string, attributes []html.Attribute) ([ value = rewriteIframeURL(attribute.Val) case tagName == "img" && attribute.Key == "src" && isValidDataAttribute(attribute.Val): value = attribute.Val - case isAnchor("a", attribute): + case tagName == "a" && attribute.Key == "href" && strings.HasPrefix(attribute.Val, "#"): value = attribute.Val isAnchorLink = true default: @@ -443,10 +443,6 @@ func isValidDataAttribute(value string) bool { }) } -func isAnchor(tagName string, attribute html.Attribute) bool { - return tagName == "a" && attribute.Key == "href" && strings.HasPrefix(attribute.Val, "#") -} - func isPositiveInteger(value string) bool { if number, err := strconv.Atoi(value); err == nil { return number > 0