Skip to content

Clarify encode_rfc2231 docstring: values are quoted even without charset or language #158783

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: The encode_rfc2231 docstring states: "If neither charset nor language is given, then s is returned as-is."

Expected: The docstring promises 'a b' unchanged when charset and language are both None.

Actual: Returns 'a%20b'.

import email.utils

s = "a b"
if not s.isascii():
    print("REFUTATION REJECTED: input is not ASCII")
else:
    actual = email.utils.encode_rfc2231(s, charset=None, language=None)
    expected = s  # Documented return when neither argument is given.
    if actual != expected:
        print("REFUTATION CONFIRMED:", repr(s), repr(actual), 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.utils:

REFUTATION CONFIRMED: 'a b' 'a%20b' 'a b'

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.utils-20261003-021105-c4

CPython versions tested on:

3.14

Operating systems tested on:

Windows

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