Metadata accepts empty BytesIO/file values although empty is not allowed

Aperta
#422 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@playlikeboy ci sta già lavorando.

Dal 4/12/2026.

  • #425 di @playlikeboy — aperta

Valutazione

Difficoltà
1/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
backend

Direzione di ricerca

Start with Metadata.get_binary_from() in src/zimscraperlib/zim/metadata.py and compare how it handles bytes with BytesIO and file inputs. The issue reports two regression tests are ready; review or run them for both empty stream types. Done means empty streams raise the same ValueError as empty bytes. An open linked pull request already covers this issue.

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

Descrizione

Metadata.get_binary_from() (src/zimscraperlib/zim/metadata.py) checks the input object instead of the bytes it read:

if not self.empty_allowed and not value:   # value is the BytesIO / file object
    raise ValueError("Missing value (empty not allowed)")
return bvalue

io.BytesIO and file objects are always truthy, so an empty stream passes the check and an empty metadata entry ends up in the ZIM, while the same empty value given as bytes is rejected:

>>> import io
>>> from zimscraperlib.zim.metadata import CustomMetadata
>>> CustomMetadata("Foo", b"")
ValueError: Missing value (empty not allowed)
>>> CustomMetadata("Foo", io.BytesIO(b"")).value
b''

An empty file opened with "rb" is accepted the same way.

Expected: empty streams are rejected like empty bytes. Checking bvalue instead of value fixes it; I have that change with two regression tests (BytesIO and file) ready and can open a PR if that works for you.

Lingua principale
Python
Stelle
33
Fork
36
Merge medio
1g 10h
PR unite (30g)
19

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 openzim/python-scraperlib

Tutte le issue di openzim/python-scraperlib

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.