Skip to content

Commit 80f74ce

Browse files
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. (cherry picked from commit 719a062) Co-authored-by: Abhilash Raj <[email protected]>
1 parent 391511c commit 80f74ce

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Lib/email/_header_value_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ def get_bare_quoted_string(value):
11891189
"expected '\"' but found '{}'".format(value))
11901190
bare_quoted_string = BareQuotedString()
11911191
value = value[1:]
1192-
if value[0] == '"':
1192+
if value and value[0] == '"':
11931193
token, value = get_qcontent(value)
11941194
bare_quoted_string.append(token)
11951195
while value and value[0] != '"':

Lib/test/test_email/test__header_value_parser.py

Lines changed: 4 additions & 0 deletions
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')
Lines changed: 2 additions & 0 deletions
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)