浏览代码

refactor(sanitizer): save some cycles in hasRequiredAttributes

There is no need to iterate twice on the attributes of source and img tags,
when we can do it once. This shouldn't bring any noticeable performances
improvements, except maybe in some extreme cases on pages with a lot of images
with a lot of attributes.
jvoisin 5 月之前
父节点
当前提交
0a15075c00
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      internal/reader/sanitizer/sanitizer.go

+ 6 - 1
internal/reader/sanitizer/sanitizer.go

@@ -467,7 +467,12 @@ func hasRequiredAttributes(tagName string, attributes []string) bool {
 	case "iframe":
 	case "iframe":
 		return slices.Contains(attributes, "src")
 		return slices.Contains(attributes, "src")
 	case "source", "img":
 	case "source", "img":
-		return slices.Contains(attributes, "src") || slices.Contains(attributes, "srcset")
+		for _, attribute := range attributes {
+			if attribute == "src" || attribute == "srcset" {
+				return true
+			}
+		}
+		return false
 	default:
 	default:
 		return true
 		return true
 	}
 	}