-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
encodings: decode utf-8 with errors='replace' when confident
"Confident" means "metadata of the document explicitly indicates that the encoding is UTF-8". This prevents feedparser from falling back to other encodings when there are only tiny errors.
- Loading branch information
1 parent
0af72dc
commit 750ca5f
Showing
7 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
changelog.d/20231227_020825_rongronggg9_utf-8_errors_replace.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Fixed | ||
----- | ||
|
||
* If the metadata of a feed explicitly indicates that the encoding is UTF-8, | ||
try decode it with ``errors="replace"`` when decoding fails. This prevents | ||
feeds from being decoded with wrong encodings when they are mostly UTF-8 but | ||
contain a few invalid bytes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/encoding/bozo_http_application_xml_encoding_utf-8_errors_replace.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Header: Content-type: application/rss+xml | ||
Description: Replace errors instead of falling back to other encodings when application/*xml w/ encoding="utf-8" header | ||
Expect: bozo and encoding == 'utf-8' and entries[0].summary == 'ð”ð“ð…-ðŸ–, ð‘ð‘¢ð‘¡ ð’†ï¿½ï¿½ð’ð’“ð’”' | ||
--> | ||
|
||
<rss version="2.0"> | ||
<channel> | ||
<item> | ||
<description><![CDATA[ ð”ð“ð…-ðŸ–, ð‘ð‘¢ð‘¡ 𒆩©ð’ð’“ð’” ]]></description> | ||
</item> | ||
</channel> | ||
</rss> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
Header: Content-type: text/rss+xml; charset="utf-8" | ||
Description: Replace errors instead of falling back to other encodings when charset="utf-8" | ||
Expect: bozo and encoding == 'utf-8' and entries[0].summary == 'ð”ð“ð…-ðŸ–, ð‘ð‘¢ð‘¡ ð’†ï¿½ï¿½ð’ð’“ð’”' | ||
--> | ||
|
||
<rss version="2.0"> | ||
<channel> | ||
<item> | ||
<description><![CDATA[ ð”ð“ð…-ðŸ–, ð‘ð‘¢ð‘¡ 𒆩©ð’ð’“ð’” ]]></description> | ||
</item> | ||
</channel> | ||
</rss> |