From 9b27bc728feb8b5d317c88a71f7581982efc04e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sat, 26 Jan 2019 02:21:12 +0000 Subject: [PATCH] Handle s with key="value"s --- botcmd.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/botcmd.py b/botcmd.py index 11978c8..7730b37 100644 --- a/botcmd.py +++ b/botcmd.py @@ -71,9 +71,15 @@ def extract_title(page_data): if maybe_tag == -1: break maybe_tag += index - if page_data[maybe_tag:maybe_tag+7].lower() == b'<title>': - title_start = maybe_tag + 7 - break + if page_data[maybe_tag:maybe_tag+6].lower() == b'<title': + # Apparently <title> can have key="value" things + # Find the end of the tag + tag_closing = page_data[maybe_tag:].find(b'>') + if tag_closing != -1: + # It is relative to maybe_tag and we want + # the string after it + title_start = maybe_tag + tag_closing + 1 + break else: index = maybe_tag + 1 @@ -104,6 +110,7 @@ def extract_title(page_data): return title def sanitize(title): + if title is None: return None return ''.join('\ufffd' if ord(c) < 32 else c for c in title) # handle_message(*, prefix, message, nick, channel, irc)