Fallback to utf-8 or iso-8859-1 if decoding using chardet-detected encoding fails
維護者通常 1 天內回覆
評估
研究方向
Start in codespell_lib/_codespell.py, especially open_with_chardet and get_lines, which appear in the traceback. Check the existing tests for hard encoding detection and run the relevant tests. Done means a decoding failure with the detected encoding falls back to utf-8 or iso-8859-1 instead of crashing; an open pull request is already linked.
由索引模型根據 Issue 內容生成。
描述
Consider file gdb/testsuite/gdb.ada/non-ascii-utf-8/pack.adb from the binutils-gdb repo.
This works without problems:
$ codespell gdb/testsuite/gdb.ada/non-ascii-utf-8/pack.adb
$
which means utf-8 decoding is used.
However, with --hard-encoding-detection we get:
$ codespell --hard-encoding-detection gdb/testsuite/gdb.ada/non-ascii-utf-8/pack.adb
Traceback (most recent call last):
File "/home/vries/codespell/python-3.9-venv/bin/codespell", line 6, in <module>
sys.exit(_script_main())
File "/home/vries/codespell/codespell.git/codespell_lib/_codespell.py", line 1294, in _script_main
return main(*sys.argv[1:])
File "/home/vries/codespell/codespell.git/codespell_lib/_codespell.py", line 1534, in main
bad_count += parse_file(
File "/home/vries/codespell/codespell.git/codespell_lib/_codespell.py", line 1217, in parse_file
fragments, encoding = file_opener.open(filename)
File "/home/vries/codespell/codespell.git/codespell_lib/_codespell.py", line 250, in open
return self.open_with_chardet(filename)
File "/home/vries/codespell/codespell.git/codespell_lib/_codespell.py", line 277, in open_with_chardet
lines = self.get_lines(f)
File "/home/vries/codespell/codespell.git/codespell_lib/_codespell.py", line 328, in get_lines
fragments.append((False, line_number, f.readlines()))
File "/usr/lib64/python3.9/encodings/cp1254.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 943: character maps to <undefined>
What happens is that chardet detects CP1254 (aka Windows-1254) encoding, but decoding using that encoding fails.
When not using --hard-encoding-detection, we first try utf-8, and if that doesn't work, warn and try iso-8859-1.
It seems logical to extend the fallback handling to --hard-encoding-detection:
$ codespell --hard-encoding-detection gdb/testsuite/gdb.ada/non-ascii-utf-8/pack.adb
WARNING: Cannot decode file using encoding "Windows-1254": gdb/testsuite/gdb.ada/non-ascii-utf-8/pack.adb
WARNING: Trying next encoding "utf-8"
$
- 主要語言
- Python
- 星號
- 2.4k
- 分支
- 531
- 平均合併
- 15 小時 55 分鐘
- 30 天內合併 PR
- 17
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 沒有貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
codespell-project/codespell 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 65/100
codespell-project/codespell#3997 ·
維護者通常 1 天內回覆
-
enhancement
難度 2/5 1-3 小時 新手友好度 63/100
codespell-project/codespell#3965 · 3 則留言 ·
維護者通常 1 天內回覆
-
Add "marcos"可能已有人在做 @ekanshul 於 21 天前認領。 未關閉dictionary
難度 2/5 1-3 小時 新手友好度 72/100
codespell-project/codespell#3920 · 3 則留言 ·
維護者通常 1 天內回覆
-
question
難度 3/5 1-2 天 新手友好度 55/100
codespell-project/codespell#4005 ·
維護者通常 1 天內回覆
-
duplicate question
難度 2/5 1-3 小時 新手友好度 35/100
codespell-project/codespell#3998 · 1 則留言 ·
維護者通常 1 天內回覆
查看 codespell-project/codespell 的全部 Issue
相似的 Issue
-
ai_p2 bug comp-datalake
難度 2/5 1-3 小時 新手友好度 85/100
ClickHouse/ClickHouse#128306 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
[bug] openlit: LLM spans from openlit 1.37+ get no OpenInference attributes, and cache and reasoning token counts are dropped可能已有人在做 @sohom-cs 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 74/100
Arize-ai/openinference#4199 · 1 個 reaction ·
維護者通常 2 天內回覆
-
難度 1/5 1 小時以內 新手友好度 82/100
MichaelYcJo/SpecSeal#1192 ·