gh-62222: Fix and extend quoted-printable decoding#152679
Open
serhiy-storchaka wants to merge 2 commits into
Open
gh-62222: Fix and extend quoted-printable decoding#152679serhiy-storchaka wants to merge 2 commits into
serhiy-storchaka wants to merge 2 commits into
Conversation
binascii.a2b_qp() and quopri now leave an invalid "=" escape in place and rescan the following character instead of consuming it, like email.quoprimime and other decoders (b'==41' now decodes to b'=A'). Add an opt-in strip_ws parameter to binascii.a2b_qp(), quopri.decode(), quopri.decodestring() and email.quoprimime.decode() to strip trailing whitespace per RFC 2045. It is false by default everywhere except email.quoprimime.decode(), preserving every existing default. Also document that email's get_payload(decode=True) does not strip trailing whitespace, contrary to RFC 2045. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Documentation build overview
5 files changed ·
|
Register the new "strip_ws" argument name in the global objects tables (make regen-global-objects), needed by static builds where binascii is compiled into the core, and replace an unresolved :func: reference to the undocumented email.quoprimime.decode with a literal. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
binascii.a2b_qp()andquoprinow leave an invalid=escape (one not followed by two hexadecimal digits or a soft line break) in place and rescan the following character instead of consuming it, likeemail.quoprimimeand other quoted-printable decoders. For exampleb'==41'now decodes tob'=A'instead ofb'=41'.A new opt-in
strip_wsparameter is added tobinascii.a2b_qp(),quopri.decode(),quopri.decodestring()andemail.quoprimime.decode(). When true, whitespace at the end of each line is stripped while decoding, as required by RFC 2045 for a quoted-printable body, while encoded whitespace (=20/=09) is preserved. It is false by default everywhere exceptemail.quoprimime.decode(), so every existing default is preserved.The documentation for
email.message.Message.get_payload(decode=True)now notes that it does not strip trailing whitespace from a quoted-printable body, contrary to RFC 2045 — this matches the behavior of common mail clients.binascii.a2b_qp()#62222