jsumners / jsumners/feedparser

unicode content is utf8-encoded then sniffed for an XML encoding

Open
#378 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-migrated
Dominant language
Python
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Hecko there!

The parsing is only happening at a later stage in our system. Prior to that we 
are working with the Unicode representation of the feed XML. Unfortunately, 
feedparser re-encodes the Unicode string using UTF-8 before feeding it into a 
StringIO, but does not remember this choice of encoding, so that it tries to 
guess the encoding again at a later stage. If the feed was not originally 
UTF-8-encoded and contains an encoding specification that feedparser 
understands, then the subsequent decoding fails.

The feed below was originally ISO-8859-15-encoded. “Umsätze” is the 
correct spelling; “UmsÀtze” is not.

{{{
>>> import feedparser
>>> import requests
>>> feedparser.__version__
'5.1.2'
>>> resp = requests.get('http://www.ibusiness.de/export/rss.xml?format=rss20')
>>> text = resp.content.decode('iso-8859-15')
>>> print text[1000:1200]
08:56:08 +0200</pubDate>
    </item>
    <item>
      <title>BVH-Prognose: ECommerce-Umsätze steigen 2012 auf 27,5 Milliarden Euro </title>
      <description>
         <![CDATA[]]>
      </descriptio
>>> feed = feedparser.parse(text)
>>> print feed.entries[1]['title']
BVH-Prognose: ECommerce-UmsÀtze steigen 2012 auf 27,5 Milliarden Euro
}}}

Thank you!

Original issue reported on code.google.com by tel...@gmail.com on 18 Oct 2012 at 4:46

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the feedparser.parse(text) example and inspect how the Unicode string is re-encoded before XML encoding is detected. Use the provided ISO-8859-15 feed and verify that the parsed title preserves “Umsätze” rather than producing mojibake.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.