Skip to content

Commit 3f9ab4b

Browse files
committed
Web: Fix crash on trailing ';' in Content-Type
1 parent faa6474 commit 3f9ab4b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

plugins/Web/plugin.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,14 @@ def getTitle(self, irc, url, raiseErrors, msg):
186186

187187
encoding = None
188188
if 'Content-Type' in fd.headers:
189-
mime_params = [p.split('=', 1)
189+
# using p.partition('=') instead of 'p.split('=', 1)' because,
190+
# unlike RFC 7231, RFC 9110 allows an empty parameter list
191+
# after ';':
192+
# * https://www.rfc-editor.org/rfc/rfc9110.html#name-media-type
193+
# * https://www.rfc-editor.org/rfc/rfc9110.html#parameter
194+
mime_params = [p.partition('=')
190195
for p in fd.headers['Content-Type'].split(';')[1:]]
191-
mime_params = {k.strip(): v.strip() for (k, v) in mime_params}
196+
mime_params = {k.strip(): v.strip() for (k, sep, v) in mime_params}
192197
if mime_params.get('charset'):
193198
encoding = mime_params['charset']
194199

plugins/Web/test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ def testtitleReddit(self):
8585
'title https://www.reddit.com/r/irc/',
8686
'Internet Relay Chat')
8787

88+
def testTitleMarcinfo(self):
89+
# Checks that we don't crash on 'Content-Type: text/html;'
90+
self.assertResponse(
91+
'title https://marc.info/?l=openbsd-tech&m=169841790407370&w=2',
92+
"'Removing syscall(2) from libc and kernel' - MARC")
93+
8894
def testTitleSnarfer(self):
8995
try:
9096
conf.supybot.plugins.Web.titleSnarfer.setValue(True)

0 commit comments

Comments
 (0)