summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-07-17 17:29:18 (GMT)
committerGitHub <noreply@github.com>2019-07-17 17:29:18 (GMT)
commit635743355d9dbffdc9aa7a2cc8de1403fbdb8d9b (patch)
tree322ad65ab62dc80e5bb1ae7d5f44b8d8e8d94abe
parent6816ca30af7705db691343100e696ea3d8f447d5 (diff)
downloadcpython-635743355d9dbffdc9aa7a2cc8de1403fbdb8d9b.zip
cpython-635743355d9dbffdc9aa7a2cc8de1403fbdb8d9b.tar.gz
cpython-635743355d9dbffdc9aa7a2cc8de1403fbdb8d9b.tar.bz2
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 719a062bcb7b08a56e6576dcd75f4244e6053209) Co-authored-by: Abhilash Raj <maxking@users.noreply.github.com>
-rw-r--r--Lib/email/_header_value_parser.py2
-rw-r--r--Lib/test/test_email/test__header_value_parser.py4
-rw-r--r--Misc/NEWS.d/next/Library/2019-07-17-06-54-43.bpo-37491.op0aMs.rst2
3 files changed, 7 insertions, 1 deletions
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py
index 2fc8abc..7dfd978 100644
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -1170,7 +1170,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] != '"':
diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py
index 6291749..f4aad85 100644
--- a/Lib/test/test_email/test__header_value_parser.py
+++ b/Lib/test/test_email/test__header_value_parser.py
@@ -503,6 +503,10 @@ class TestParser(TestParserMixin, TestEmailBase):
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')
diff --git a/Misc/NEWS.d/next/Library/2019-07-17-06-54-43.bpo-37491.op0aMs.rst b/Misc/NEWS.d/next/Library/2019-07-17-06-54-43.bpo-37491.op0aMs.rst
new file mode 100644
index 0000000..af4287b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-07-17-06-54-43.bpo-37491.op0aMs.rst
@@ -0,0 +1,2 @@
+Fix ``IndexError`` when parsing email headers with unexpectedly ending
+bare-quoted string value. Patch by Abhilash Raj.