Skip to content

Commit

Permalink
Fix IndexError when parsing unexpectedly ending quoted-string. (GH-14813
Browse files Browse the repository at this point in the history
)

This exception was caused because the input ended unexpectedly with only one
single quote instead of a pair with some value inside it.
  • Loading branch information
maxking authored and warsaw committed Jul 17, 2019
1 parent a4a994b commit 719a062
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/email/_header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ def get_bare_quoted_string(value):
"expected '\"' but found '{}'".format(value))
bare_quoted_string = BareQuotedString()
value = value[1:]
if value[0] == '"':
if value and value[0] == '"':
token, value = get_qcontent(value)
bare_quoted_string.append(token)
while value and value[0] != '"':
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_email/test__header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@ def test_get_bare_quoted_string_only_quotes(self):
self._test_get_x(parser.get_bare_quoted_string,
'""', '""', '', [], '')

def test_get_bare_quoted_string_missing_endquotes(self):
self._test_get_x(parser.get_bare_quoted_string,
'"', '""', '', [errors.InvalidHeaderDefect], '')

def test_get_bare_quoted_string_following_wsp_preserved(self):
self._test_get_x(parser.get_bare_quoted_string,
'"foo"\t bar', '"foo"', 'foo', [], '\t bar')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``IndexError`` when parsing email headers with unexpectedly ending
bare-quoted string value. Patch by Abhilash Raj.

0 comments on commit 719a062

Please sign in to comment.