Skip to content

Fix missing unquote for empty files - #264

Merged
simleo merged 3 commits into
ResearchObject:masterfrom
LauLauThom:master
Oct 14, 2026
Merged

simleo merged 3 commits into
ResearchObject:masterfrom
LauLauThom:master

Conversation

@LauLauThom

Copy link
Copy Markdown
Contributor

Hello,

I noticed a small issue when adding empty files containing special character in their filename or path (such as brackets).
The path is not unquoted contrary to the other non-empty files, so these files can end up in different directory or not have the expected filename.

This is illustrated by this script

"""Illustrates the rocrate-py bug: 0-byte files are written to the zip with a still-quoted path."""

import tempfile
import zipfile
from pathlib import Path

from rocrate.rocrate import ROCrate

with tempfile.TemporaryDirectory() as tmp:
    tmp_dir = Path(tmp)
    
    empty_file = tmp_dir / "empty.txt"
    empty_file.touch()
    
    non_empty_file = tmp_dir / "non_empty.txt"
    non_empty_file.write_text("data")

    crate = ROCrate()
    # parentheses are percent-encoded in the entity @id by rocrate-py
    crate.add_file(empty_file, dest_path="assays/assay_A_(B)/empty.txt")
    crate.add_file(non_empty_file, dest_path="assays/assay_A_(B)/non_empty.txt")

    zip_path = tmp_dir / "crate.zip"
    crate.write_zip(zip_path)

    for name in zipfile.ZipFile(zip_path).namelist():
        if name.startswith("assays/"):
            print(name)

# Output with the buggy version:
#   assays/assay_A_%28B%29/empty.txt      <- wrong, still quoted
#   assays/assay_A_(B)/non_empty.txt      <- correct

The PR includes a modification of the test testing empty files, to illustrate the issue.
The modified test raises a KeyError with the current version of the lib, which is fixed by the PR.

@simleo
simleo merged commit e8696f5 into ResearchObject:master Oct 14, 2026
13 checks passed
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.

2 participants