`iso2022_jp_3` encodes U+9B1D but decodes the result as U+9B1C
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 84/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- python
研究方向
閱讀 Modules/cjkcodecs/_codecs_iso2022.c 中 jisx0213_2000_2_decoder 附近的程式碼,並將 plane 2 的對應邏輯與 plane 1 解碼器比較。Issue 指出缺少的 else 和受影響的儲存格;使用 PR #160155 中的測試 RoundTripBugs.test_iso2022_jp_3_mapping 進行回歸檢查。完成標準是 iso2022_jp_3 能正確往返轉換 U+9B1D,同時保留預期的 2000 對應行為。
由索引模型根據 Issue 內容生成。
描述
Bug description
>>> '鬝'.encode('iso2022_jp_3')
b'\x1b$(P};\x1b(B'
>>> _.decode('iso2022_jp_3')
'鬜'
>>> hex(ord(_))
'0x9b1c'
JIS X 0213:2004 changed plane 2 row 93 cell 27 (0x7D3B) from U+9B1D to U+9B1C, and CPython emulates the 2000 mapping in the codecs named after that edition. euc_jisx0213 and shift_jisx0213 do so in both directions:
>>> '鬝'.encode('euc_jisx0213').decode('euc_jisx0213')
'鬝'
>>> '鬜'.encode('euc_jisx0213')
Traceback (most recent call last):
File "<python-input-5>", line 1, in <module>
'鬜'.encode('euc_jisx0213')
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'euc_jisx0213' codec can't encode character '鬜' in position 0: illegal multibyte sequence
iso2022_jp_3 only does it when encoding: it accepts U+9B1D and rejects U+9B1C like the other 2000 codecs, but decodes 0x7D3B as U+9B1C, as iso2022_jp_2004 does.
The cause is in jisx0213_2000_2_decoder, Modules/cjkcodecs/_codecs_iso2022.c lines 728-739. The EMULATE_JISX0213_2000_DECODE_PLANE2_CHAR macro expands to an if that sets u = 0x9B1D for this cell, but the table lookup that follows it is a plain if (TRYMAP_DEC_ST(jisx0213_2_bmp, ...)) rather than else if, so it runs regardless and overwrites u with the 2004 value. The plane 1 decoder just above uses else if after its emulation macro and is fine, as are the EUC and Shift_JIS codecs, which use the OUTCHAR form of the macro in _codecs_jp.c. So the fix is the missing else.
A scan of every code point through iso2022_jp_3 found no other character that comes back different, so it should be just this one cell.
Found by the Hypothesis tests in #160155, where it is pinned as RoundTripBugs.test_iso2022_jp_3_mapping under expectedFailure and kept out of the generated text otherwise.
CPython versions tested on
CPython main (6e1bd24e4d8)
Operating systems tested on
Linux
- 主要語言
- Python
- 星號
- 77.7k
- 分支
- 38.3k
- 平均合併
- 12 小時 12 分鐘
- 30 天內合併 PR
- 650
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/cpython 的其他 Issue
-
type-bug
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
tests topic-profiling type-bug
難度 2/5 1-3 小時 新手友好度 78/100
python/cpython#160334 · 1 則留言 ·
維護者通常 1 天內回覆
-
interpreter-core type-feature
難度 1/5 1 小時以內 新手友好度 78/100
python/cpython#160109 · 1 則留言 ·
維護者通常 1 天內回覆
-
extension-modules type-bug
難度 2/5 1-3 小時 新手友好度 72/100
python/cpython#160001 · 3 則留言 ·
維護者通常 1 天內回覆
-
stdlib topic-XML type-bug
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
相似的 Issue
-
難度 1/5 1-3 小時 新手友好度 85/100
WLAN-Pi/wlanpi-profiler#341 ·
維護者通常 1 天內回覆
-
Memory leak: the shared `validation_aborted_error` keeps every traceback it is raised through可能已有人在做 @Fire162 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
graphql-python/graphql-core#287 ·
-
難度 2/5 1-3 小時 新手友好度 67/100
roman-corgi/ctc-dip#160 ·
維護者通常 1 天內回覆
-
render_findings.py reads and writes in the host's default encoding, so findings.html breaks on a cp1252 Windows host可能已有人在做 @Aaqibhafeezkhan 今天認領。 未關閉bug good first issue mentored python size: XS up-for-grabs
難度 2/5 1-3 小時 新手友好度 75/100
dheerajjha/mcp-migrate#366 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆