Skip to content

Commit 1a80e5e

Browse files
author
Vladimir Prelovac
committed
test(encoding): add tests for non-UTF8 XML declaration handling
1 parent d2d0aba commit 1a80e5e

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tests/test_encoding.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from fastfeedparser import parse
2+
3+
4+
def test_parse_str_with_non_utf8_xml_declaration():
5+
xml = (
6+
'<?xml version="1.0" encoding="iso-8859-1"?>'
7+
'<rss version="2.0">'
8+
"<channel>"
9+
"<title>café</title>"
10+
"<item><title>café</title></item>"
11+
"</channel>"
12+
"</rss>"
13+
)
14+
feed = parse(xml)
15+
assert feed.feed.title == "café"
16+
assert feed.entries[0].title == "café"
17+
18+
19+
def test_parse_bytes_with_non_utf8_encoding():
20+
xml_bytes = (
21+
b'<?xml version="1.0" encoding="iso-8859-1"?>'
22+
b'<rss version="2.0">'
23+
b"<channel>"
24+
b"<title>caf\xe9</title>"
25+
b"<item><title>caf\xe9</title></item>"
26+
b"</channel>"
27+
b"</rss>"
28+
)
29+
feed = parse(xml_bytes)
30+
assert feed.feed.title == "café"
31+
assert feed.entries[0].title == "café"
32+

0 commit comments

Comments
 (0)