Skip to content

Commit 6357433

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 <maxking@users.noreply.github.com>
1 parent 6816ca3 commit 6357433

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

Lib/email/_header_value_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ def get_bare_quoted_string(value):
11701170
"expected '\"' but found '{}'".format(value))
11711171
bare_quoted_string = BareQuotedString()
11721172
value = value[1:]
1173-
if value[0] == '"':
1173+
if value and value[0] == '"':
11741174
token, value = get_qcontent(value)
11751175
bare_quoted_string.append(token)
11761176
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
@@ -503,6 +503,10 @@ def test_get_bare_quoted_string_only_quotes(self):
503503
self._test_get_x(parser.get_bare_quoted_string,
504504
'""', '""', '', [], '')
505505

506+
def test_get_bare_quoted_string_missing_endquotes(self):
507+
self._test_get_x(parser.get_bare_quoted_string,
508+
'"', '""', '', [errors.InvalidHeaderDefect], '')
509+
506510
def test_get_bare_quoted_string_following_wsp_preserved(self):
507511
self._test_get_x(parser.get_bare_quoted_string,
508512
'"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)