scipp / scippnexus

h5py-like utility for NeXus files with seamless scipp integration
https://scipp.github.io/scippnexus/
BSD 3-Clause "New" or "Revised" License
3 stars 3 forks source link

Repeated forward slashes become absolute paths #208

Closed g5t closed 2 months ago

g5t commented 2 months ago

Following up on #204 and the fix in #205, I noticed that a path with repeated forward slashes will silently ignore any valid path before the last such '/' and treat the rest of the path specification as an absolute path. E.g., a NeXus HDF5 file with an NXinstrument group at /entry/instrument opened as file will pass the following assert statement

assert id(file['/entry/instrument']) == id(file['/entry//entry/instrument'])

this behavior is contrary to file system paths under unix-like systems which treat repeated path separators as if they were singular.

MridulS commented 2 months ago

Maybe we can use pathlib to santize these things? I know they aren't path objects, but it should take care of all these corner cases.

jl-wynen commented 2 months ago

Yes:

PurePosixPath('/entry//entry/instrument').as_posix()

Also takes care of the final slash