Skip to content

email: unquoted apostrophe in a MIME parameter value is dropped under policy.default #153823

Description

@abdoulrasheed

Bug report

Bug description:

With policy.default a parameter value containing an unquoted apostrophe is not returned, while compat32 returns it. The apostrophe is not a tspecial (RFC 2045), so a bare value such as filename=O'Brien.pdf is a valid token and should be parsed whole.

import email, email.policy
msg = email.message_from_string(
    "Content-Disposition: attachment; filename=O'Brien.pdf\n\nbody\n", 
    policy=email.policy.default
)
msg.get_filename() is None
True

Under email.policy.compat32 the same string returns "O'Brien.pdf". Quoting the value (filename="O'Brien.pdf") works under both policies.

For a multipart message an unquoted apostrophe in the boundary is not recognized, so is_multipart() returns False and the message is not split.

ASPECIALS in Lib/email/_header_value_parser.py includes "'" unconditionally, which terminates the value.

Observed on 3.16.0a0.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Fields

    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