mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
test(sanitizer): enhance tests for image width and height attributes
This commit is contained in:
parent
8c3f280f32
commit
cb617ff6e0
2 changed files with 48 additions and 9 deletions
|
@ -73,7 +73,7 @@ func TestImgWithWidthAndHeightAttribute(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestImgWithWidthAndHeightAttributeLargerThanMinifluxLayout(t *testing.T) {
|
||||
func TestImgWithWidthAttributeLargerThanMinifluxLayout(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="1200" height="675">`
|
||||
expected := `<img src="https://example.org/image.png" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
@ -93,7 +93,17 @@ func TestImgWithIncorrectWidthAndHeightAttribute(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestImgWithEmptywidthAndHeightAttribute(t *testing.T) {
|
||||
func TestImgWithIncorrectWidthAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="10px" height="20">`
|
||||
expected := `<img src="https://example.org/image.png" height="20" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -103,6 +113,36 @@ func TestImgWithEmptywidthAndHeightAttribute(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestImgWithIncorrectHeightAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="10" height="20px">`
|
||||
expected := `<img src="https://example.org/image.png" width="10" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImgWithNegativeWidthAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="-10" height="20">`
|
||||
expected := `<img src="https://example.org/image.png" height="20" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImgWithNegativeHeightAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="10" height="-20">`
|
||||
expected := `<img src="https://example.org/image.png" width="10" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImgWithTextDataURL(t *testing.T) {
|
||||
input := `<img src="data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==" alt="Example">`
|
||||
expected := ``
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue