Просмотр исходного кода

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.
jvoisin 1 год назад
Родитель
Сommit
902ca63c45
1 измененных файлов с 1 добавлено и 5 удалено
  1. 1 5
      internal/reader/sanitizer/sanitizer.go

+ 1 - 5
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