diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index a3e258e4d..9deb19fda 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -186,9 +186,14 @@ class Web(callbacks.PluginRegexp): encoding = None if 'Content-Type' in fd.headers: - mime_params = [p.split('=', 1) + # using p.partition('=') instead of 'p.split('=', 1)' because, + # unlike RFC 7231, RFC 9110 allows an empty parameter list + # after ';': + # * https://www.rfc-editor.org/rfc/rfc9110.html#name-media-type + # * https://www.rfc-editor.org/rfc/rfc9110.html#parameter + mime_params = [p.partition('=') for p in fd.headers['Content-Type'].split(';')[1:]] - mime_params = {k.strip(): v.strip() for (k, v) in mime_params} + mime_params = {k.strip(): v.strip() for (k, sep, v) in mime_params} if mime_params.get('charset'): encoding = mime_params['charset'] diff --git a/plugins/Web/test.py b/plugins/Web/test.py index 88fd10cac..e8ecdff33 100644 --- a/plugins/Web/test.py +++ b/plugins/Web/test.py @@ -85,6 +85,12 @@ class WebTestCase(ChannelPluginTestCase): 'title https://www.reddit.com/r/irc/', 'Internet Relay Chat') + def testTitleMarcinfo(self): + # Checks that we don't crash on 'Content-Type: text/html;' + self.assertResponse( + 'title https://marc.info/?l=openbsd-tech&m=169841790407370&w=2', + "'Removing syscall(2) from libc and kernel' - MARC") + def testTitleSnarfer(self): try: conf.supybot.plugins.Web.titleSnarfer.setValue(True)