[critical] walkGlob doesn't work with un-normalized paths (eg containing `//`); os.walkFiles works
timotheecour opened this issue · 0 comments
timotheecour commented
the //
in input pattern makes walkGlob not work; it should work, like other tools (eg: unix ls
on cmdline, or os.walkFiles)
# D20200115T205019
import pkg/glob
import std/os
proc main()=
let pattern2 = "/Users/timothee/temp//d18_D20200115T203454/*.log"
echo "walkGlob:"
for file in walkGlob(pattern2):
echo (file: file)
echo "walkFiles:"
for file2 in walkFiles(pattern2):
echo (file2: file2)
main()
output:
walkGlob:
walkFiles:
(file2: "/Users/timothee/temp//d18_D20200115T203454/foo1.foo2.foo3.log")
(file2: "/Users/timothee/temp//d18_D20200115T203454/foo1.foo2.log")
(file2: "/Users/timothee/temp//d18_D20200115T203454/foo1.log")
note
double slashes can and do occur in practice, eg if user has an env var MYDIR=/path/to/foo/
and enters a path like $MYDIR/foo.txt
;
this is not uncommon practice, because ending dirs in /
(eg MYDIR=/path/to/foo/
) makes sense, and concatenating with /
(eg $MYDIR/foo.txt
) also makes sense in case user is not sure whether $MYDIR
ended in a /
I can point to more stackoverflow issues pointing to how this does happen in practice, if needed
proposal
walkGlob shd probably simply call normalizedPath
on the input pattern before further processing