Skip to content

Commit

Permalink
Check if Message.get_params return 3-tuple instead of str on `p…
Browse files Browse the repository at this point in the history
…arse_options_header` (#79)

* Fixing issue #78

* Added test for parse_options_header

* Added a comment clarifying a condition in parse_options_header

* Fixed a typo

---------

Co-authored-by: lorenpike <[email protected]>
  • Loading branch information
lorenpike and lorenpike authored Feb 9, 2024
1 parent cb0b7cf commit 26d664f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions multipart/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ def parse_options_header(value: Union[str, bytes]) -> Tuple[bytes, Dict[bytes, b
options = {}
for param in params:
key, value = param
# If the value returned from get_params() is a 3-tuple, the last
# element corresponds to the value.
# See: https://docs.python.org/3/library/email.compat32-message.html
if isinstance(value, tuple):
value = value[-1]
# If the value is a filename, we need to fix a bug on IE6 that sends
# the full file path instead of the filename.
if key == 'filename':
Expand Down
5 changes: 5 additions & 0 deletions tests/test_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ def test_redos_attack_header(self):
# If vulnerable, this test wouldn't finish, the line above would hang
self.assertIn(b'"\\', p[b'!'])

def test_handles_rfc_2231(self):
t, p = parse_options_header(b'text/plain; param*=us-ascii\'en-us\'encoded%20message')

self.assertEqual(p[b'param'], b'encoded message')


class TestBaseParser(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 26d664f

Please sign in to comment.