GNU bug report logs -
#57102
29.0.50; Peculiar file-name-split edge case
Previous Next
Full log
View this message in rfc822 format
The current behaviour of file-name-split is based on a purely textual splitting on "/" which isn't as useful as basing it on actual file name components. For instance, the root component of a Posix file name is "/", not "". Looking at other languages and libraries is very much encouraged; they vary a lot in the amount of thought that has gone into their design.
Ideally we'd have a split function (the name is a placeholder for now) where:
(split "/a/b/c") -> ("/" "a" "b" "c")
(split "a/b/c/") -> ("a" "b" "c" "")
(split "/") -> ("/" "")
and, because repeated slashes mean the same thing as a single one in Posix except at the beginning,
(split "//a//b//") -> ("//" "a" "b" "")
An accompanying join operation would be the inverse, sort of:
(join "/" "a" "b" "c") -> "/a/b/c"
(join "a" "b" "") -> "a/b/"
where empty strings are ignored except at the end:
(join "" "a" "" "" "b") -> "a/b"
(join "a" "b" "" "") -> "a/b/"
Pre-joined chunks can be joined too:
(join "/a/b" "c/d/" "e") -> "/a/b/c/d/e"
Maybe components with a leading slash start over from the root:
(join "/" "a" "/b" "c") -> "/a/b/c" ?
(join "/" "a" "/b" "c") -> "/b/c" ?
Python's os.path.join does the latter; it's probably a good idea.
Now `file-name-concat` almost works like `join` above but not quite. Adding a new function is likely better than making compromises.
On Windows I'd expect that
(split "c:\\a\\b") -> ("c:\\" "a" "b")
(split "c:\\") -> ("c:\\" "")
but it's a bit complicated and then we have all the UNC path variants to deal with; a platform expert should be consulted.
This bug report was last modified 2 years and 355 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.