mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
feat(sanitizer): add validation for empty width and height attributes in img tags
This commit is contained in:
parent
d53fd17e10
commit
cecc18420d
2 changed files with 13 additions and 0 deletions
|
@ -541,6 +541,9 @@ func isValidDataAttribute(value string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func isPositiveInteger(value string) bool {
|
func isPositiveInteger(value string) bool {
|
||||||
|
if value == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if number, err := strconv.Atoi(value); err == nil {
|
if number, err := strconv.Atoi(value); err == nil {
|
||||||
return number > 0
|
return number > 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,16 @@ func TestImgWithIncorrectWidthAndHeightAttribute(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestImgWithEmptywidthAndHeightAttribute(t *testing.T) {
|
||||||
|
input := `<img src="https://example.org/image.png" width="" height="">`
|
||||||
|
expected := `<img src="https://example.org/image.png" loading="lazy">`
|
||||||
|
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf(`Wrong output: %s`, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestImgWithTextDataURL(t *testing.T) {
|
func TestImgWithTextDataURL(t *testing.T) {
|
||||||
input := `<img src="data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==" alt="Example">`
|
input := `<img src="data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==" alt="Example">`
|
||||||
expected := ``
|
expected := ``
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue