GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `hz` codec encodes `~` as a single `~` when the output buffer fills mid-escape · Issue #160518 · python/cpython

hz codec encodes ~ as a single ~ when the output buffer fills mid-escape #160518

New issue
Copy link
New issue
Copy link
Closed
#160519
Closed
hz codec encodes ~ as a single ~ when the output buffer fills mid-escape#160518
#160519
Copy link
Assignees
gpshead
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@gpshead
gpshead
opened on Oct 23, 2026
Issue body actions

Bug report

Bug description:

The hz encoder writes the ~~ escape for a ~ as two separate bytes and consumes the character after the first one. If the output buffer becomes full between the two, the encoder is called again at the next character and the second ~ is never written. The result is a bare ~ that the decoder combines with the byte after it, so the data decodes to different text or fails to decode. It needs text that mixes ASCII and Chinese characters (plain ASCII or plain Chinese never fills the initial buffer) with a ~ at the wrong offset.

text = "a中" * 7 + "xx" + "~{"
data = text.encode("hz")
print(data[-8:])                  # b'VP~}xx~{', should end in b'xx~~{'
print(data.decode("hz") == text)  # False

With "xxx" instead of "xx" the output is correct. The two-step write dates from gh-74189.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-160518: Fix hz encoder dropping half of the ~~ escape #160519
  • [3.15] gh-160518: Fix hz encoder dropping half of the ~~ escape (GH-160519) #161002
  • [3.14] gh-160518: Fix hz encoder dropping half of the ~~ escape (GH-160519) #161003

Activity

  1. gpshead
    self-assigned this
    on Oct 23, 2026
  2. gpshead
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    topic-unicode
    on Oct 23, 2026
  3. StanFromIreland
    added this to Codecs and encodings issueson Oct 23, 2026
  4. StanFromIreland
    removed
    topic-unicode
    on Oct 23, 2026
  5. gpshead
    added a commit that references this issue on Oct 31, 2026

    gh-160518: Fix hz encoder dropping half of the ~~ escape (GH-160519)

    1259f16
  6. gpshead
    closed this as completedin #160519on Oct 31, 2026
  7. github-project-automation
    moved this to Done in Codecs and encodings issueson Oct 31, 2026
  8. gpshead
    added 2 commits that reference this issue on Nov 1, 2026

    [3.14] gh-160518: Fix hz encoder dropping half of the ~~ escape (GH-1…

    922b7f7

    [3.15] gh-160518: Fix hz encoder dropping half of the ~~ escape (GH-1…

    3135a08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @gpshead
    gpshead

Labels

extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

  • Codecs and encodings issues
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.