Web: Fix encoding issue on Python 2. Closes GH-1359.

This commit is contained in:
Valentin Lorentz 2019-02-01 21:02:57 +01:00
parent 624553c069
commit 0f82f89eec

View File

@ -156,14 +156,20 @@ class Web(callbacks.PluginRegexp):
'replace')
except UnicodeDecodeError:
pass
parser = Title()
if minisix.PY3 and isinstance(text, bytes):
if raiseErrors:
irc.error(_('Could not guess the page\'s encoding. (Try '
'installing python-charade.)'), Raise=True)
else:
return None
parser.feed(text)
try:
parser = Title()
parser.feed(text)
except UnicodeDecodeError:
# Workaround for Python 2
# https://github.com/ProgVal/Limnoria/issues/1359
parser = Title()
parser.feed(text.encode('utf8'))
parser.close()
title = utils.str.normalizeWhitespace(''.join(parser.data).strip())
if title: