From 0f82f89eec8d606c175a4f225ba19dc21c486938 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 1 Feb 2019 21:02:57 +0100 Subject: [PATCH] Web: Fix encoding issue on Python 2. Closes GH-1359. --- plugins/Web/plugin.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index 6f85f2af7..1ac362714 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -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: