Skip to content

Commit 719a062

Browse files
maxkingwarsaw
authored andcommitted
Fix IndexError when parsing unexpectedly ending quoted-string. (GH-14813)
This exception was caused because the input ended unexpectedly with only one single quote instead of a pair with some value inside it.
1 parent a4a994b commit 719a062

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Lib/email/_header_value_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ def get_bare_quoted_string(value):
11911191
"expected '\"' but found '{}'".format(value))
11921192
bare_quoted_string = BareQuotedString()
11931193
value = value[1:]
1194-
if value[0] == '"':
1194+
if value and value[0] == '"':
11951195
token, value = get_qcontent(value)
11961196
bare_quoted_string.append(token)
11971197
while value and value[0] != '"':

Lib/test/test_email/test__header_value_parser.py

+4
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,10 @@ def test_get_bare_quoted_string_only_quotes(self):
522522
self._test_get_x(parser.get_bare_quoted_string,
523523
'""', '""', '', [], '')
524524

525+
def test_get_bare_quoted_string_missing_endquotes(self):
526+
self._test_get_x(parser.get_bare_quoted_string,
527+
'"', '""', '', [errors.InvalidHeaderDefect], '')
528+
525529
def test_get_bare_quoted_string_following_wsp_preserved(self):
526530
self._test_get_x(parser.get_bare_quoted_string,
527531
'"foo"\t bar', '"foo"', 'foo', [], '\t bar')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``IndexError`` when parsing email headers with unexpectedly ending
2+
bare-quoted string value. Patch by Abhilash Raj.

0 commit comments

Comments
 (0)