GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — ISO-2022 encoders accept U+001B (and `iso2022_kr` U+000E/U+000F) although the encoding cannot represent them · Issue #160302 · python/cpython Open Labels extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug descriptionIn ISO 2022, the bytes I would expect that attempting to encode these by themselves (or in some other invalid configuration) to be a failure state and raise What they actually do is write the control character through as a bare byte, because the encoder's ASCII fast path accepts every code point below 0x80, >>> '\x1b'.encode('iso2022_jp') b'\x1b' >>> b'\x1b'.decode('iso2022_jp') Traceback (most recent call last): File "<python-input-2>", line 1, in <module> b'\x1b'.decode('iso2022_jp') ~~~~~~~~^^^^^^^^^^^^^^ UnicodeDecodeError: 'iso2022_jp' codec can't decode byte 0x1b in position 0: incomplete multibyte sequence Followed by the right ASCII characters, it is an escape sequence, and the text that follows is decoded in the wrong character set: >>> 'x\x1b$B$"'.encode('iso2022_jp') b'x\x1b$B$"' >>> _.decode('iso2022_jp') 'xあ' And in front of a real designation sequence it makes the decoder consume that sequence as text: >>> '\x1b\xa0'.encode('iso2022_jp_2004') b'\x1b\x1b$(Q)"\x1b(B' >>> _.decode('iso2022_jp_2004') '\x1b\x1b$(Q)"' Every >>> '\x0e'.encode('iso2022_kr') b'\x0e' >>> _.decode('iso2022_kr') '' >>> 'a\x0f가'.encode('iso2022_kr').decode('iso2022_kr') 'a가' I do not think this can be fixed on the decoding side: the second example shows that a decoder cannot tell a stray ESC from a real one, so only refusing to encode these characters makes the round trip hold. Raising is a behavior change for text that currently encodes without complaint, but what it currently encodes to is misread by any ISO-2022 reader, not just Python's. For comparison, Found by the Hypothesis tests in #160155, where it is pinned as Linked PRsActivity
MetadataMetadataAssigneesLabelsextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue 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. |