]> granicus.if.org Git - python/commitdiff
Fix IndexError when parsing unexpectedly ending quoted-string. (GH-14813)
authorAbhilash Raj <maxking@users.noreply.github.com>
Wed, 17 Jul 2019 16:48:52 +0000 (09:48 -0700)
committerBarry Warsaw <barry@python.org>
Wed, 17 Jul 2019 16:48:52 +0000 (09:48 -0700)
This exception was caused because the input ended unexpectedly with only one
single quote instead of a pair with some value inside it.

Lib/email/_header_value_parser.py
Lib/test/test_email/test__header_value_parser.py
Misc/NEWS.d/next/Library/2019-07-17-06-54-43.bpo-37491.op0aMs.rst [new file with mode: 0644]

index 66b042ee0ef03cc17f664797919f5c706f55373a..daff57b9cfa215a9c3dcb4c29f7edd3e5825506b 100644 (file)
@@ -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] != '"':
index a83915d6d059cf05fdddcbea68cd9f6973d64e7b..4fa56b16c47854f6956e3fae50cbe658bfec3498 100644 (file)
@@ -522,6 +522,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 (file)
index 0000000..af4287b
--- /dev/null
@@ -0,0 +1,2 @@
+Fix ``IndexError`` when parsing email headers with unexpectedly ending
+bare-quoted string value. Patch by Abhilash Raj.