Skip to content

email.headerregistry fails to combine RFC 2231 continuations with mixed-case parameter names #158709

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: The email.headerregistry documentation, under ParameterizedMIMEHeader.params, states: “Parameter names are always mapped to lower case” and “Parameter values are decoded if necessary according to RFC 2231.” RFC 2231 continuation decoding applies to the case-insensitive MIME parameter names.

Expected: params['filename'] == 'helloworld'

Actual: params['filename'] == 'world'

from email.headerregistry import HeaderRegistry

a, b = "hello", "world"
parts = [("filename*0*", "us-ascii''" + a), ("FILENAME*1*", b)]
value = "attachment; " + "; ".join(k + "=" + v for k, v in parts)
valid = all(s and s.isascii() and s.isalpha() for s in (a, b))
valid &= [k.lower() for k, _ in parts] == ["filename*0*", "filename*1*"]
if not valid:
    print("REFUTATION REJECTED: invalid RFC 2231 continuation input")
else:
    expected = a + b
    actual = HeaderRegistry()("Content-Disposition", value).params.get("filename")
    if actual != expected:
        print("REFUTATION CONFIRMED:", repr(value), "actual =", repr(actual),
              "expected =", repr(expected))
    else:
        print("REFUTATION REJECTED: actual matches documented expectation")

Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library email.headerregistry:

REFUTATION CONFIRMED: "attachment; filename*0*=us-ascii''hello; FILENAME*1*=world" actual = 'world' expected = 'helloworld'

This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/email.headerregistry-20261003-195236-c1

CPython versions tested on:

3.14

Operating systems tested on:

Windows

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions