[Python-checkins] gh-93010: InvalidHeaderError used but nonexistent (GH-93015)

miss-islington webhook-mailer at python.org
Mon May 23 12:57:17 EDT 2022


https://github.com/python/cpython/commit/a509d2674a388a13ca55451480673e2af2ab2875
commit: a509d2674a388a13ca55451480673e2af2ab2875
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-05-23T09:57:12-07:00
summary:

gh-93010: InvalidHeaderError used but nonexistent (GH-93015)


* fix issue 93010

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
(cherry picked from commit 71abeb0895f7563dc5ac4b4f077a8f87dab57e7a)

Co-authored-by: oda-gitso <105083118+oda-gitso at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2022-05-20-15-52-43.gh-issue-93010.WF-cAc.rst
M Lib/email/_header_value_parser.py
M Lib/test/test_email/test_email.py

diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py
index 8a8fb8bc42a95..e637e6df06612 100644
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -2379,7 +2379,7 @@ def get_section(value):
         digits += value[0]
         value = value[1:]
     if digits[0] == '0' and digits != '0':
-        section.defects.append(errors.InvalidHeaderError(
+        section.defects.append(errors.InvalidHeaderDefect(
                 "section number has an invalid leading 0"))
     section.number = int(digits)
     section.append(ValueTerminal(digits, 'digits'))
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 69f883a3673f2..2b1e2b864feda 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -19,24 +19,25 @@
 import email.policy
 
 from email.charset import Charset
-from email.header import Header, decode_header, make_header
-from email.parser import Parser, HeaderParser
 from email.generator import Generator, DecodedGenerator, BytesGenerator
+from email.header import Header, decode_header, make_header
+from email.headerregistry import HeaderRegistry
 from email.message import Message
 from email.mime.application import MIMEApplication
 from email.mime.audio import MIMEAudio
-from email.mime.text import MIMEText
-from email.mime.image import MIMEImage
 from email.mime.base import MIMEBase
+from email.mime.image import MIMEImage
 from email.mime.message import MIMEMessage
 from email.mime.multipart import MIMEMultipart
 from email.mime.nonmultipart import MIMENonMultipart
-from email import utils
-from email import errors
+from email.mime.text import MIMEText
+from email.parser import Parser, HeaderParser
+from email import base64mime
 from email import encoders
+from email import errors
 from email import iterators
-from email import base64mime
 from email import quoprimime
+from email import utils
 
 from test.support import threading_helper
 from test.support.os_helper import unlink
@@ -5541,7 +5542,12 @@ def test_long_headers_flatten(self):
         result = fp.getvalue()
         self._signed_parts_eq(original, result)
 
-
+class TestHeaderRegistry(TestEmailBase):
+    # See issue gh-93010.
+    def test_HeaderRegistry(self):
+        reg = HeaderRegistry()
+        a = reg('Content-Disposition', 'attachment; 0*00="foo"')
+        self.assertIsInstance(a.defects[0], errors.InvalidHeaderDefect)
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2022-05-20-15-52-43.gh-issue-93010.WF-cAc.rst b/Misc/NEWS.d/next/Library/2022-05-20-15-52-43.gh-issue-93010.WF-cAc.rst
new file mode 100644
index 0000000000000..24208b5160ed5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-05-20-15-52-43.gh-issue-93010.WF-cAc.rst
@@ -0,0 +1 @@
+In a very special case, the email package tried to append the nonexistent ``InvalidHeaderError`` to the defect list. It should have been ``InvalidHeaderDefect``.



More information about the Python-checkins mailing list