Skip to content

Commit 690be1e

Browse files
TomNicholasclaude
andcommitted
Add regression test for list_dir corrupting directory names (zarr-developers#3753)
ObjectStore.list_dir uses lstrip(prefix) which strips individual characters rather than a prefix string, corrupting child directory names when the prefix shares characters with them. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 48e7f4d commit 690be1e

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎tests/test_store/test_object.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ async def test_store_getsize_prefix(self, store: ObjectStore) -> None:
8686
assert total_size == len(buf) * 2
8787

8888

89+
async def test_list_dir_with_nested_prefix(tmpdir):
90+
"""Regression test for https://github.com/zarr-developers/zarr-python/issues/3753.
91+
92+
list_dir must not corrupt directory names when prefix shares characters
93+
with child names, which happened because lstrip strips characters not prefixes.
94+
"""
95+
store = ObjectStore(LocalStore(prefix=str(tmpdir)))
96+
97+
buf = cpu.Buffer.from_bytes(b"\x01")
98+
await store.set("subdir/data.zarr/zarr.json", buf)
99+
await store.set("subdir/data.zarr/temp/zarr.json", buf)
100+
await store.set("subdir/data.zarr/temp/c/0/0", buf)
101+
102+
results = sorted([item async for item in store.list_dir("subdir/data.zarr")])
103+
assert "temp" in results, f"Expected 'temp' in {results}"
104+
assert "zarr.json" in results
105+
106+
89107
@pytest.mark.slow_hypothesis
90108
def test_zarr_hierarchy():
91109
sync_store = ObjectStore(MemoryStore())

0 commit comments

Comments
 (0)