mirror of https://github.com/miniflux/v2.git
Add support for SVG icons with data url without encoding
This commit is contained in:
parent
c60b3f52a5
commit
7650c81ad9
|
@ -194,6 +194,8 @@ func parseImageDataURL(value string) (*model.Icon, error) {
|
||||||
return nil, fmt.Errorf(`icon: unable to decode data URL %q`, value)
|
return nil, fmt.Errorf(`icon: unable to decode data URL %q`, value)
|
||||||
}
|
}
|
||||||
blob = []byte(decodedData)
|
blob = []byte(decodedData)
|
||||||
|
case "utf8":
|
||||||
|
blob = []byte(data)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf(`icon: unsupported data URL encoding %q`, value)
|
return nil, fmt.Errorf(`icon: unsupported data URL encoding %q`, value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,26 @@ func TestParseImageDataURLWithNoEncoding(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseImageWithRawSVGEncodedInUTF8(t *testing.T) {
|
||||||
|
iconURL := `data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 456 456'><circle></circle></svg>`
|
||||||
|
icon, err := parseImageDataURL(iconURL)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf(`We should be able to parse valid data URL: %v`, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if icon.MimeType != "image/svg+xml" {
|
||||||
|
t.Fatal(`Invalid mime type parsed`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if icon.Hash == "" {
|
||||||
|
t.Fatal(`Image hash should be computed`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(icon.Content) != `<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 456 456'><circle></circle></svg>` {
|
||||||
|
t.Fatal(`Invalid SVG content`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseImageDataURLWithNoMediaTypeAndNoEncoding(t *testing.T) {
|
func TestParseImageDataURLWithNoMediaTypeAndNoEncoding(t *testing.T) {
|
||||||
iconURL := `data:,Hello%2C%20World%21`
|
iconURL := `data:,Hello%2C%20World%21`
|
||||||
_, err := parseImageDataURL(iconURL)
|
_, err := parseImageDataURL(iconURL)
|
||||||
|
|
Loading…
Reference in New Issue