mirror of
https://github.com/miniflux/v2.git
synced 2025-07-12 16:58:36 +00:00
sanitizer: handle image URLs in srcset attribute with comma
This commit is contained in:
parent
d85908e3de
commit
806a069785
6 changed files with 212 additions and 88 deletions
85
reader/sanitizer/srcset_test.go
Normal file
85
reader/sanitizer/srcset_test.go
Normal file
|
@ -0,0 +1,85 @@
|
|||
// Copyright 2022 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sanitizer
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseSrcSetAttributeWithRelativeURLs(t *testing.T) {
|
||||
input := `example-320w.jpg, example-480w.jpg 1.5x, example-640,w.jpg 2x, example-640w.jpg 640w`
|
||||
candidates := ParseSrcSetAttribute(input)
|
||||
|
||||
if len(candidates) != 4 {
|
||||
t.Error(`Incorrect number of candidates`)
|
||||
}
|
||||
|
||||
if candidates.String() != `example-320w.jpg, example-480w.jpg 1.5x, example-640,w.jpg 2x, example-640w.jpg 640w` {
|
||||
t.Errorf(`Unexpected string output`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSrcSetAttributeWithAbsoluteURLs(t *testing.T) {
|
||||
input := `http://example.org/example-320w.jpg 320w, http://example.org/example-480w.jpg 1.5x`
|
||||
candidates := ParseSrcSetAttribute(input)
|
||||
|
||||
if len(candidates) != 2 {
|
||||
t.Error(`Incorrect number of candidates`)
|
||||
}
|
||||
|
||||
if candidates.String() != `http://example.org/example-320w.jpg 320w, http://example.org/example-480w.jpg 1.5x` {
|
||||
t.Errorf(`Unexpected string output`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSrcSetAttributeWithOneCandidate(t *testing.T) {
|
||||
input := `http://example.org/example-320w.jpg`
|
||||
candidates := ParseSrcSetAttribute(input)
|
||||
|
||||
if len(candidates) != 1 {
|
||||
t.Error(`Incorrect number of candidates`)
|
||||
}
|
||||
|
||||
if candidates.String() != `http://example.org/example-320w.jpg` {
|
||||
t.Errorf(`Unexpected string output`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSrcSetAttributeWithCommaURL(t *testing.T) {
|
||||
input := `http://example.org/example,a:b/d.jpg , example-480w.jpg 1.5x`
|
||||
candidates := ParseSrcSetAttribute(input)
|
||||
|
||||
if len(candidates) != 2 {
|
||||
t.Error(`Incorrect number of candidates`)
|
||||
}
|
||||
|
||||
if candidates.String() != `http://example.org/example,a:b/d.jpg, example-480w.jpg 1.5x` {
|
||||
t.Errorf(`Unexpected string output`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSrcSetAttributeWithIncorrectDescriptor(t *testing.T) {
|
||||
input := `http://example.org/example-320w.jpg test`
|
||||
candidates := ParseSrcSetAttribute(input)
|
||||
|
||||
if len(candidates) != 0 {
|
||||
t.Error(`Incorrect number of candidates`)
|
||||
}
|
||||
|
||||
if candidates.String() != `` {
|
||||
t.Errorf(`Unexpected string output`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSrcSetAttributeWithTooManyDescriptors(t *testing.T) {
|
||||
input := `http://example.org/example-320w.jpg 10w 1x`
|
||||
candidates := ParseSrcSetAttribute(input)
|
||||
|
||||
if len(candidates) != 0 {
|
||||
t.Error(`Incorrect number of candidates`)
|
||||
}
|
||||
|
||||
if candidates.String() != `` {
|
||||
t.Errorf(`Unexpected string output`)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue