Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Fallback to utf-8 or iso-8859-1 if decoding using chardet-detected encoding fails

Aperta
#3,985 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@ekanshul ci sta già lavorando.

Dal 20/9/2026.

  • #4030 di @ekanshul — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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"
$
Lingua principale
Python
Stelle
2.4k
Fork
531
Merge medio
15h 55m
PR unite (30g)
17

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Nessun Dockerfile né file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di codespell-project/codespell

Tutte le issue di codespell-project/codespell

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.