Skip to content

gh-135854: Fix function email.message.Message.get_boundary strips boundaries twice #135891

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Lib/email/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def get_boundary(self, failobj=None):
parameter, and it is unquoted.
"""
missing = object()
boundary = self.get_param('boundary', missing)
boundary = self.get_param('boundary', missing, unquote=False)
if boundary is missing:
return failobj
# RFC 2046 says that boundaries may begin but not end in w/s
Expand Down
36 changes: 36 additions & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,42 @@ def test_boundary_with_leading_space(self):
eq(msg.get_boundary(), ' XXXX')
eq(len(msg.get_payload()), 2)

def test_boundary_stripped_only_once(self):
eq = self.assertEqual
msg = email.message_from_string(textwrap.dedent('''\
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="<>"

--<>
Content-Type: text/plain


--<>
Content-Type: text/plain

--<>--
'''))
self.assertTrue(msg.is_multipart())
eq(msg.get_boundary(), '<>')
eq(len(msg.get_payload()), 2)

msg = email.message_from_string(textwrap.dedent('''\
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=<"">

--""
Content-Type: text/plain


--""
Content-Type: text/plain

--""--
'''))
self.assertTrue(msg.is_multipart())
eq(msg.get_boundary(), '""')
eq(len(msg.get_payload()), 2)

def test_boundary_without_trailing_newline(self):
m = Parser().parsestr("""\
Content-Type: multipart/mixed; boundary="===============0012394164=="
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :func:`email.message.Message.get_boundary` strips boundaries twice.
Loading