mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-18 06:30:57 +01:00
Web: Fix crash on trailing ';' in Content-Type
This commit is contained in:
parent
faa6474271
commit
3f9ab4b89c
@ -186,9 +186,14 @@ class Web(callbacks.PluginRegexp):
|
|||||||
|
|
||||||
encoding = None
|
encoding = None
|
||||||
if 'Content-Type' in fd.headers:
|
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:]]
|
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'):
|
if mime_params.get('charset'):
|
||||||
encoding = mime_params['charset']
|
encoding = mime_params['charset']
|
||||||
|
|
||||||
|
@ -85,6 +85,12 @@ class WebTestCase(ChannelPluginTestCase):
|
|||||||
'title https://www.reddit.com/r/irc/',
|
'title https://www.reddit.com/r/irc/',
|
||||||
'Internet Relay Chat')
|
'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):
|
def testTitleSnarfer(self):
|
||||||
try:
|
try:
|
||||||
conf.supybot.plugins.Web.titleSnarfer.setValue(True)
|
conf.supybot.plugins.Web.titleSnarfer.setValue(True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user