Skip to content

Commit 71abeb0

Browse files
oda-gitsoblurb-it[bot]
oda-gitso
andauthored
gh-93010: InvalidHeaderError used but nonexistent (#93015)
* fix issue 93010 Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
1 parent 949dbf9 commit 71abeb0

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

Lib/email/_header_value_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2379,7 +2379,7 @@ def get_section(value):
23792379
digits += value[0]
23802380
value = value[1:]
23812381
if digits[0] == '0' and digits != '0':
2382-
section.defects.append(errors.InvalidHeaderError(
2382+
section.defects.append(errors.InvalidHeaderDefect(
23832383
"section number has an invalid leading 0"))
23842384
section.number = int(digits)
23852385
section.append(ValueTerminal(digits, 'digits'))

Lib/test/test_email/test_email.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,25 @@
1919
import email.policy
2020

2121
from email.charset import Charset
22-
from email.header import Header, decode_header, make_header
23-
from email.parser import Parser, HeaderParser
2422
from email.generator import Generator, DecodedGenerator, BytesGenerator
23+
from email.header import Header, decode_header, make_header
24+
from email.headerregistry import HeaderRegistry
2525
from email.message import Message
2626
from email.mime.application import MIMEApplication
2727
from email.mime.audio import MIMEAudio
28-
from email.mime.text import MIMEText
29-
from email.mime.image import MIMEImage
3028
from email.mime.base import MIMEBase
29+
from email.mime.image import MIMEImage
3130
from email.mime.message import MIMEMessage
3231
from email.mime.multipart import MIMEMultipart
3332
from email.mime.nonmultipart import MIMENonMultipart
34-
from email import utils
35-
from email import errors
33+
from email.mime.text import MIMEText
34+
from email.parser import Parser, HeaderParser
35+
from email import base64mime
3636
from email import encoders
37+
from email import errors
3738
from email import iterators
38-
from email import base64mime
3939
from email import quoprimime
40+
from email import utils
4041

4142
from test.support import threading_helper
4243
from test.support.os_helper import unlink
@@ -5541,7 +5542,12 @@ def test_long_headers_flatten(self):
55415542
result = fp.getvalue()
55425543
self._signed_parts_eq(original, result)
55435544

5544-
5545+
class TestHeaderRegistry(TestEmailBase):
5546+
# See issue gh-93010.
5547+
def test_HeaderRegistry(self):
5548+
reg = HeaderRegistry()
5549+
a = reg('Content-Disposition', 'attachment; 0*00="foo"')
5550+
self.assertIsInstance(a.defects[0], errors.InvalidHeaderDefect)
55455551

55465552
if __name__ == '__main__':
55475553
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In a very special case, the email package tried to append the nonexistent ``InvalidHeaderError`` to the defect list. It should have been ``InvalidHeaderDefect``.

0 commit comments

Comments
 (0)