The punycode incremental encoder and decoder transform each chunk separately
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
- #160599 di @OsmnvAslan — chiusa senza merge
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- backend, internationalization
Direzione di ricerca
Read Lib/encodings/punycode.py around lines 226–234 and the buffered incremental encoder and decoder base classes. Check how idna buffers input and how test_codecs.py marks punycode as broken in stateful mode. Implement buffering until final for both directions, then verify chunked input produces the same result as the whole-string transform.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug description
encodings.punycode registers an IncrementalEncoder and IncrementalDecoder, but they just run the whole-string transform on every chunk they are given, so anything fed in more than one piece comes out wrong:
>>> import codecs
>>> 'ab'.encode('punycode')
b'ab-'
>>> encoder = codecs.getincrementalencoder('punycode')()
>>> encoder.encode('a') + encoder.encode('b', final=True)
b'a-b-'
>>> b'a-b-'.decode('punycode')
'a-b'
Punycode encodes the positions of the non-ASCII characters relative to the whole label, so a chunk cannot be encoded without the rest of the string; the same goes for decoding. The classes are two lines each, Lib/encodings/punycode.py lines 226-234, and ignore final altogether. This is half known: test_codecs.py lists punycode in broken_unicode_with_stateful ("encodings that don't work in stateful mode") and skips the chunked part of test_basics for it, but nothing says so in the docs, and the classes are still registered and handed out by codecs.getincrementalencoder(), codecs.iterencode() and StreamWriter.
I think the right fix is to buffer until final (the BufferedIncrementalEncoder and BufferedIncrementalDecoder base classes make that a few lines: _buffer_encode returns (b'', 0) until final), since that keeps codecs.iterencode, StreamWriter and friends working for anyone who hands them the whole label at once, which is presumably every current user. The idna codec already does something like it, buffering up to each ..
Related: #64331 (many incremental codecs do not handle fragmented data) mentions punycode in passing, in a list taken from that same test_codecs.py entry, but does not go into it.
Found by the Hypothesis tests in #160155, where it is pinned as PunycodeIncrementalBug.test_chunked_encode under expectedFailure; the chunked tests there leave punycode out otherwise.
CPython versions tested on
CPython main (6e1bd24e4d8)
Operating systems tested on
Linux
- Lingua principale
- Python
- Stelle
- 77.7k
- Fork
- 38.3k
- Merge medio
- 11h 58m
- PR unite (30g)
- 672
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python/cpython
-
topic-socket type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
python/cpython#160561 · 7 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
tests topic-profiling type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
python/cpython#160334 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
extension-modules type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
Remove unused FVS_* macrosApertainterpreter-core type-feature
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
python/cpython#160109 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
extension-modules type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
python/cpython#160001 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di python/cpython
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Arekkazu/sgpmp-backend#744 ·
I maintainer di solito rispondono entro 1 giorno
-
Review backlog (security): master-branch remote guard trusts unbound provenance package fieldApertaagent/reviewer
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
projectbluefin/utah-packages#634 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue help wanted
Difficoltà 2/5 1-2 giorni Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
home-assistant/core#188613 ·
I maintainer di solito rispondono entro 1 giorno
-
WebsiteApertagood first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 91/100
TanbirRamim/open-source-radar#314 ·
I maintainer di solito rispondono entro 1 giorno