Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-134152: Fix UnboundLocalError in email._header_value_parser _get_ptext_to_endchars #134233

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 3 commits into
base: main
Choose a base branch
Loading
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: 2 additions & 0 deletions 2 Lib/email/_header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,8 @@ def _get_ptext_to_endchars(value, endchars):
a flag that is True iff there were any quoted printables decoded.

"""
if not value:
return '', '', False
fragment, *remainder = _wsp_splitter(value, 1)
vchars = []
escape = False
Expand Down
33 changes: 33 additions & 0 deletions 33 Lib/test/test_email/test__header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,19 @@ def test_get_qp_ctext_non_printables(self):
[errors.NonPrintableDefect], ')')
self.assertEqual(ptext.defects[0].non_printables[0], '\x00')

def test_get_qp_ctext_close_paren_only(self):
self._test_get_x(parser.get_qp_ctext,
')', '', ' ', [], ')')

def test_get_qp_ctext_open_paren_only(self):
self._test_get_x(parser.get_qp_ctext,
'(', '', ' ', [], '(')

def test_get_qp_ctext_no_end_char(self):
self._test_get_x(parser.get_qp_ctext,
'', '', ' ', [], '')


# get_qcontent

def test_get_qcontent_only(self):
Expand Down Expand Up @@ -503,6 +516,14 @@ def test_get_qcontent_non_printables(self):
[errors.NonPrintableDefect], '"')
self.assertEqual(ptext.defects[0].non_printables[0], '\x00')

def test_get_qcontent_empty(self):
self._test_get_x(parser.get_qcontent,
'"', '', '', [], '"')

def test_get_qcontent_no_end_char(self):
self._test_get_x(parser.get_qcontent,
'', '', '', [], '')

# get_atext

def test_get_atext_only(self):
Expand Down Expand Up @@ -1283,6 +1304,18 @@ def test_get_dtext_open_bracket_mid_word(self):
self._test_get_x(parser.get_dtext,
'foo[bar', 'foo', 'foo', [], '[bar')

def test_get_dtext_open_bracket_only(self):
self._test_get_x(parser.get_dtext,
'[', '', '', [], '[')

def test_get_dtext_close_bracket_only(self):
self._test_get_x(parser.get_dtext,
']', '', '', [], ']')

def test_get_dtext_empty(self):
self._test_get_x(parser.get_dtext,
'', '', '', [], '')

# get_domain_literal

def test_get_domain_literal_only(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed :exc:`UnboundLocalError` that could occur during :mod:`email` header
parsing if an expected trailing delimiter is missing in some contexts.
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.