Skip to content

Reject empty stream values in binary Metadata - #425

Open
playlikeboy wants to merge 2 commits into
openzim:mainfrom
playlikeboy:metadata-reject-empty-streams
Open

playlikeboy wants to merge 2 commits into
openzim:mainfrom
playlikeboy:metadata-reject-empty-streams

Conversation

@playlikeboy

Copy link
Copy Markdown

Fix #422

Metadata rejected an empty bytes value when empty values are not allowed, but an empty io.BytesIO (or other file-like value) passed the check. The check ran not value on the original value, and a stream object is always truthy. It now checks the bytes read from the value (bvalue), so both forms are handled the same way.

Changes:

  • src/zimscraperlib/zim/metadata.py: test emptiness on bvalue instead of value.
  • tests/zim/test_metadata.py: two tests, one with an empty io.BytesIO and one with an empty file-like object, both now raising ValueError; metadata that allows empty values is unaffected.
  • CHANGELOG.md: entry under Unreleased / Fixed.

pytest tests/zim/test_metadata.py: 193 passed. In the full tests/zim run, test_start_logs_metadata_log_contents[tags0] fails locally on main as well, so it is unrelated to this change.

Metadata.get_binary_from() checked the original value for emptiness
instead of the bytes it read from it. An io.BytesIO or file object is
always truthy, so an empty stream passed the "empty not allowed" check
and an empty metadata entry ended up in the ZIM, while an empty bytes
value was correctly rejected.

Check the read bytes instead.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant