Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

`iso2022_jp_3` encodes U+9B1D but decodes the result as U+9B1C

未關閉 適合新手
#160,306 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 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 內容生成。

描述

extension-modules type-bug

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

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python/cpython 的其他 Issue

查看 python/cpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。