diff --git a/internal/reader/sanitizer/sanitizer.go b/internal/reader/sanitizer/sanitizer.go index 4a8154c3..5ab0b723 100644 --- a/internal/reader/sanitizer/sanitizer.go +++ b/internal/reader/sanitizer/sanitizer.go @@ -296,9 +296,9 @@ func hasRequiredAttributes(tagName string, attributes []string) bool { switch tagName { case "a": return slices.Contains(attributes, "href") - case "iframe", "img": + case "iframe": return slices.Contains(attributes, "src") - case "source": + case "source", "img": return slices.Contains(attributes, "src") || slices.Contains(attributes, "srcset") default: return true diff --git a/internal/reader/sanitizer/sanitizer_test.go b/internal/reader/sanitizer/sanitizer_test.go index cd5250a0..5e0de29d 100644 --- a/internal/reader/sanitizer/sanitizer_test.go +++ b/internal/reader/sanitizer/sanitizer_test.go @@ -119,7 +119,7 @@ func TestImgWithDataURL(t *testing.T) { } } -func TestImgWithSrcset(t *testing.T) { +func TestImgWithSrcsetAttribute(t *testing.T) { input := `Example` expected := `Example` output := Sanitize("http://example.org/", input) @@ -129,6 +129,16 @@ func TestImgWithSrcset(t *testing.T) { } } +func TestImgWithSrcsetAndNoSrcAttribute(t *testing.T) { + input := `Example` + expected := `Example` + output := Sanitize("http://example.org/", input) + + if output != expected { + t.Errorf(`Wrong output: %s`, output) + } +} + func TestSourceWithSrcsetAndMedia(t *testing.T) { input := `` expected := ``