diff --git a/reader/sanitizer/sanitizer.go b/reader/sanitizer/sanitizer.go
index f133247b..ad7afbca 100644
--- a/reader/sanitizer/sanitizer.go
+++ b/reader/sanitizer/sanitizer.go
@@ -100,6 +100,12 @@ func Sanitize(baseURL, input string) string {
func sanitizeAttributes(baseURL, tagName string, attributes []html.Attribute) ([]string, string) {
var htmlAttrs, attrNames []string
var err error
+ var isImageLargerThanLayout bool
+
+ if tagName == "img" {
+ imgWidth := getIntegerAttributeValue("width", attributes)
+ isImageLargerThanLayout = imgWidth > 750
+ }
for _, attribute := range attributes {
value := attribute.Val
@@ -112,8 +118,14 @@ func sanitizeAttributes(baseURL, tagName string, attributes []html.Attribute) ([
value = sanitizeSrcsetAttr(baseURL, value)
}
- if tagName == "img" && (attribute.Key == "width" || attribute.Key == "height") && !isPositiveInteger(value) {
- continue
+ if tagName == "img" && (attribute.Key == "width" || attribute.Key == "height") {
+ if !isPositiveInteger(value) {
+ continue
+ }
+
+ if isImageLargerThanLayout {
+ continue
+ }
}
if isExternalResourceAttribute(attribute.Key) {
@@ -486,3 +498,17 @@ func isPositiveInteger(value string) bool {
}
return false
}
+
+func getAttributeValue(name string, attributes []html.Attribute) string {
+ for _, attribute := range attributes {
+ if attribute.Key == name {
+ return attribute.Val
+ }
+ }
+ return ""
+}
+
+func getIntegerAttributeValue(name string, attributes []html.Attribute) int {
+ number, _ := strconv.Atoi(getAttributeValue(name, attributes))
+ return number
+}
diff --git a/reader/sanitizer/sanitizer_test.go b/reader/sanitizer/sanitizer_test.go
index 695c1e49..74452590 100644
--- a/reader/sanitizer/sanitizer_test.go
+++ b/reader/sanitizer/sanitizer_test.go
@@ -25,6 +25,16 @@ func TestImgWithWidthAndHeightAttribute(t *testing.T) {
}
}
+func TestImgWithWidthAndHeightAttributeLargerThanMinifluxLayout(t *testing.T) {
+ input := `
`
+ expected := `
`
+ output := Sanitize("http://example.org/", input)
+
+ if output != expected {
+ t.Errorf(`Wrong output: %s`, output)
+ }
+}
+
func TestImgWithIncorrectWidthAndHeightAttribute(t *testing.T) {
input := `
`
expected := `
`
@@ -77,7 +87,7 @@ func TestSourceWithSrcsetAndMedia(t *testing.T) {
func TestMediumImgWithSrcset(t *testing.T) {
input := `
`
- expected := `
`
+ expected := `
`
output := Sanitize("http://example.org/", input)
if output != expected {