You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
hz codec encodes ~ as a single ~ when the output buffer fills mid-escape #160518
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.
Activity