Skip to content

email.quoprimime.decode() leaves stray \r when eol='\r\n' #145831

@stefanzetzsche

Description

@stefanzetzsche

Bug report

Bug description:

Issue

email.quoprimime.decode() strips only one character when removing a trailing line ending that wasn't in the original input. When eol='\r\n' (2 characters), only the \n is removed, leaving a stray \r.

The bug is in this line:

decoded = decoded[:-1]

It should be decoded[:-len(eol)].

Reproducer

import email.quoprimime as qp
print(repr(qp.decode('abc', eol='\r\n')))  # 'abc\r' — expected 'abc'
print(repr(qp.decode('a\nb', eol='\r\n')))  # 'a\r\nb\r' — trailing \r is spurious

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions