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時間 5分
- マージ済み PR(30日)
- 18
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 が 20 日前に担当しました。 オープン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 日以内に返信
codespell-project/codespell の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Graphify-Labs/graphify#4860 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
:bug: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
scikit-image/scikit-image#8377 ·
メンテナーはふだん 1 日以内に返信
-
Ingredient import validation accepts negative nutrient values and NaN対応中かも @LukeSekai が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
wger-project/wger#2564 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
apache/ponymail-foal#351 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
メンテナーはふだん 4 日以内に返信