Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

AttributeError: module 'email.errors' has no attribute 'InvalidHeaderError'. #93010

Copy link
Copy link
@The-Compiler

Description

@The-Compiler
Issue body actions

Bug report

email._header_value_parser tries to raise errors.InvalidHeaderError, but that does not exist (and as far as I can tell, never did):

>>> from email.headerregistry import HeaderRegistry
>>> reg = HeaderRegistry()
>>> reg('Content-Disposition', 'attachment; 0*00="foo"')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/email/headerregistry.py", line 604, in __call__
    return self[name](name, value)
  File "/usr/lib/python3.10/email/headerregistry.py", line 192, in __new__
    cls.parse(value, kwds)
  File "/usr/lib/python3.10/email/headerregistry.py", line 448, in parse
    kwds['parse_tree'] = parse_tree = cls.value_parser(value)
  File "/usr/lib/python3.10/email/_header_value_parser.py", line 2705, in parse_content_disposition_header
    disp_header.append(parse_mime_parameters(value[1:]))
  File "/usr/lib/python3.10/email/_header_value_parser.py", line 2569, in parse_mime_parameters
    token, value = get_parameter(value)
  File "/usr/lib/python3.10/email/_header_value_parser.py", line 2431, in get_parameter
    token, value = get_section(value)
  File "/usr/lib/python3.10/email/_header_value_parser.py", line 2382, in get_section
    section.defects.append(errors.InvalidHeaderError(
AttributeError: module 'email.errors' has no attribute 'InvalidHeaderError'. Did you mean: 'InvalidHeaderDefect'?

Code:

if digits[0] == '0' and digits != '0':
section.defects.append(errors.InvalidHeaderError(
"section number has an invalid leading 0"))

This was added in 97f43c0 by @bitdancer pretty much some 10 years ago, and I don't think it ever worked (but nor could I find anyone running into this so far): The git history doesn't know anything about an email.errors.InvalidHeaderError.

Found via Hypothesis while testing my own parsing code - cc @Zac-HD if you want to see another instance of "the curse of hypothesis" 😉

Your environment

  • CPython versions tested on: 3.7.13, 3.8.13, 3.9.13, 3.10.4, 3.11.0b1
  • Operating system and architecture: Archlinux, x86_64
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.