Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if Message.get_params return 3-tuple instead of str on parse_options_header #79

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions multipart/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,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]
lorenpike marked this conversation as resolved.
Show resolved Hide resolved
# 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 @@ -271,6 +271,11 @@ def test_handles_ie6_bug(self):

self.assertEqual(p[b'filename'], b'file.txt')

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
Loading