Skip to content

gh-160522: Restore CJK encoder state after a failed incremental encode - #160523

Merged
gpshead merged 1 commit into
python:mainfrom
gpshead:scanfix-multibytecodec-zdf903iu
Oct 31, 2026
Merged

gpshead merged 1 commit into
python:mainfrom
gpshead:scanfix-multibytecodec-zdf903iu

Conversation

@gpshead

@gpshead gpshead commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

encoder_encode_stateful() now saves the codec state on entry and puts it back when the call fails, as it already did for its pending buffer. A failed call discards its output, so keeping the state it reached made the next IncrementalEncoder.encode() or StreamWriter.write() skip the escape sequence. The decoders are not changed: they keep the state reached before the error, which is right for a caller that goes on with the following bytes of the same stream.

Fixes #160522

ANT-2026-ZDF903IU

… encode

A failed IncrementalEncoder.encode() or StreamWriter.write() of a
stateful CJK codec kept the shift state reached before the error
although its output was discarded.
@gpshead gpshead added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 23, 2026
@gpshead gpshead self-assigned this Oct 23, 2026
@gpshead
gpshead marked this pull request as ready for review October 23, 2026 22:05
@gpshead
gpshead requested a review from corona10 as a code owner October 23, 2026 22:05
@github-project-automation github-project-automation Bot moved this to Todo in Sprint Oct 23, 2026
@gpshead
gpshead merged commit 5b25582 into python:main Oct 31, 2026
67 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@github-project-automation github-project-automation Bot moved this from Todo to Done in Sprint Oct 31, 2026
@gpshead
gpshead deleted the scanfix-multibytecodec-zdf903iu branch October 31, 2026 12:54
@bedevere-app

bedevere-app Bot commented Oct 31, 2026

Copy link
Copy Markdown

GH-161000 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 31, 2026
@bedevere-app

bedevere-app Bot commented Oct 31, 2026

Copy link
Copy Markdown

GH-161001 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 31, 2026
gpshead added a commit that referenced this pull request Oct 31, 2026
…l encode (GH-160523) (#161001)

gh-160522: Restore CJK encoder state after a failed incremental encode (GH-160523)

A failed IncrementalEncoder.encode() or StreamWriter.write() of a
stateful CJK codec kept the shift state reached before the error
although its output was discarded.
(cherry picked from commit 5b25582)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
gpshead added a commit that referenced this pull request Oct 31, 2026
…l encode (GH-160523) (#161000)

gh-160522: Restore CJK encoder state after a failed incremental encode (GH-160523)

A failed IncrementalEncoder.encode() or StreamWriter.write() of a
stateful CJK codec kept the shift state reached before the error
although its output was discarded.
(cherry picked from commit 5b25582)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Stateful CJK incremental encoders keep the shift state after a failed encode()

1 participant