iconv codecs write an error handler's replacement in a non-initial shift state
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
An error handler's replacement bytes are copied to the output without returning it to the initial shift state first, so in a stateful encoding they are read back as encoded data.
>>> '中😀中'.encode('iso-2022-cn', 'replace')
b'\x1b$)A\x0eVP?\x1b$)A\x0eVP\x0f'
>>> _.decode('iso-2022-cn')
UnicodeDecodeError: 'iso-2022-cn' codec can't decode byte 0x3f in position 7: invalid multibyte sequence
>>> '中😀中'.encode('iso-2022-cn', 'backslashreplace').decode('iso-2022-cn')
'中苷鞍氨娑鞍中'
The built-in codec of the same family shifts back to ASCII first:
>>> '日😀日'.encode('iso2022_jp', 'replace') # built-in
b'\x1b$BF|\x1b(B?\x1b$BF|\x1b(B'
>>> '日😀日'.encode('iconv:ISO-2022-JP', 'replace') # iconv
b'\x1b$BF|?\x1b$BF|\x1b(B'
_PyUnicode_EncodeIconv() does reset the shift state after each handled error, but with a NULL output buffer, so the conversion forgets the state while the stream never gets the closing sequence.
This affects the ISO-2022 family and the stateful EBCDIC code pages (CP1364, CP1371, ...). ignore is unaffected, it injects nothing.
Linked PRs
- gh-155005
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu tại điểm vào _PyUnicode_EncodeIconv() và tái hiện các ví dụ ISO-2022 và EBCDIC có trạng thái trong báo cáo. So sánh đầu ra của các byte thay thế và việc giải mã với hành vi ISO-2022-JP tích hợp sẵn; hoàn thành khi các thay thế được xử lý quay về trạng thái shift ban đầu, còn ignore vẫn không bị ảnh hưởng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- internationalization
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100