Skip to content

Commit 0a15075

Browse files
jvoisinfguillot
authored andcommitted
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.
1 parent b1fda59 commit 0a15075

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

internal/reader/sanitizer/sanitizer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,12 @@ func hasRequiredAttributes(tagName string, attributes []string) bool {
467467
case "iframe":
468468
return slices.Contains(attributes, "src")
469469
case "source", "img":
470-
return slices.Contains(attributes, "src") || slices.Contains(attributes, "srcset")
470+
for _, attribute := range attributes {
471+
if attribute == "src" || attribute == "srcset" {
472+
return true
473+
}
474+
}
475+
return false
471476
default:
472477
return true
473478
}

0 commit comments

Comments
 (0)