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

Offen
#422 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@playlikeboy arbeitet bereits daran.

Seit 04.12.2026.

  • #425 von @playlikeboy — offen

Bewertung

Schwierigkeit
1/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
backend

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
33
Forks
36
Ø Merge
1 T. 10 Std.
Gemergte PRs (30 T.)
19

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus openzim/python-scraperlib

Alle Issues in openzim/python-scraperlib

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.