Skip to content

Commit

Permalink
utils/web.py: Attempt to fix handling of RSS feeds using broken entit…
Browse files Browse the repository at this point in the history
…y references.
  • Loading branch information
progval committed Nov 26, 2013
1 parent ff5d83e commit 42b8a06
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/utils/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,14 @@ def handle_data(self, data):
self.data.append(data)

def handle_entityref(self, data):
self.data.append(unichr(htmlentitydefs.name2codepoint[data]))
if data in htmlentitydefs.name2codepoint:
self.data.append(unichr(htmlentitydefs.name2codepoint[data]))
elif sys.version_info[0] >= 3 and isinstance(data, bytes):
self.data.append(data.decode())
elif sys.version_info[0] < 3 and isinstance(data, str):
self.data.append(data.decode('utf8', errors='replace'))
else:
self.data.append(data)

def getText(self):
text = ''.join(self.data).strip()
Expand Down

0 comments on commit 42b8a06

Please sign in to comment.