From a4497810e292e2d7b5a891f9d0f3a896c1c3978f Mon Sep 17 00:00:00 2001 From: lorenpike Date: Wed, 7 Feb 2024 09:04:44 -0800 Subject: [PATCH 1/4] Fixing issue #78 --- multipart/multipart.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/multipart/multipart.py b/multipart/multipart.py index e1d10fc..5651552 100644 --- a/multipart/multipart.py +++ b/multipart/multipart.py @@ -110,6 +110,8 @@ def parse_options_header(value: Union[str, bytes]) -> Tuple[bytes, Dict[bytes, b options = {} for param in params: key, value = param + 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': From ed5fa20170f6ebd90f5ceea21622307508cf7d92 Mon Sep 17 00:00:00 2001 From: lorenpike Date: Wed, 7 Feb 2024 12:52:18 -0800 Subject: [PATCH 2/4] Added test for parse_options_header --- tests/test_multipart.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_multipart.py b/tests/test_multipart.py index 031515b..61c9570 100644 --- a/tests/test_multipart.py +++ b/tests/test_multipart.py @@ -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): From 1394db9a30791fd9ac01ecf9be8f5cd3f14db2e7 Mon Sep 17 00:00:00 2001 From: lorenpike Date: Fri, 9 Feb 2024 06:50:11 -0800 Subject: [PATCH 3/4] Added a comment clarifying a condition in parse_options_header --- multipart/multipart.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/multipart/multipart.py b/multipart/multipart.py index 5651552..be0f01f 100644 --- a/multipart/multipart.py +++ b/multipart/multipart.py @@ -110,6 +110,9 @@ def parse_options_header(value: Union[str, bytes]) -> Tuple[bytes, Dict[bytes, b options = {} for param in params: key, value = param + # If the value return 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 From 24d5ec7f533f0788a563a2717a153b5daa8928e0 Mon Sep 17 00:00:00 2001 From: lorenpike Date: Fri, 9 Feb 2024 06:52:00 -0800 Subject: [PATCH 4/4] Fixed a typo --- multipart/multipart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multipart/multipart.py b/multipart/multipart.py index be0f01f..caf1fdf 100644 --- a/multipart/multipart.py +++ b/multipart/multipart.py @@ -110,7 +110,7 @@ def parse_options_header(value: Union[str, bytes]) -> Tuple[bytes, Dict[bytes, b options = {} for param in params: key, value = param - # If the value return from get_params() is a 3-tuple, the last + # 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):