From: "Mattias Engdegård" <mattiase@acm.org>
To: Philip Kaludercic <philipk@posteo.net>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, 57102@debbugs.gnu.org
Subject: bug#57102: 29.0.50; Peculiar file-name-split edge case
Date: Sat, 13 Aug 2022 19:08:00 +0200 [thread overview]
Message-ID: <4ECBBAD8-732D-4235-BB7C-003E226543C0@acm.org> (raw)
In-Reply-To: <87a68cwlnv.fsf@posteo.net>
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.
next prev parent reply other threads:[~2022-08-13 17:08 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-10 8:24 bug#57102: 29.0.50; Peculiar file-name-split edge case Philip Kaludercic
2022-08-12 15:35 ` Lars Ingebrigtsen
2022-08-12 15:56 ` Philip Kaludercic
2022-08-12 15:59 ` Lars Ingebrigtsen
2022-08-12 16:29 ` Philip Kaludercic
2022-08-13 11:44 ` Lars Ingebrigtsen
2022-08-13 13:24 ` Philip Kaludercic
2022-08-15 5:54 ` Lars Ingebrigtsen
2022-08-15 11:28 ` Lars Ingebrigtsen
2022-08-15 15:57 ` Philip Kaludercic
2022-08-15 11:35 ` Eli Zaretskii
2022-08-17 10:55 ` Lars Ingebrigtsen
2022-08-13 18:06 ` Augusto Stoffel
2022-08-14 6:24 ` Philip Kaludercic
2022-08-13 17:08 ` Mattias Engdegård [this message]
2022-09-25 12:06 ` Stefan Kangas
2022-09-26 10:41 ` Lars Ingebrigtsen
2022-09-26 11:14 ` Stefan Kangas
2022-09-26 11:59 ` Lars Ingebrigtsen
2022-09-26 12:07 ` Mattias Engdegård
2022-09-26 12:27 ` Gregory Heytings
2022-09-29 3:02 ` Richard Stallman
2022-09-29 6:20 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4ECBBAD8-732D-4235-BB7C-003E226543C0@acm.org \
--to=mattiase@acm.org \
--cc=57102@debbugs.gnu.org \
--cc=larsi@gnus.org \
--cc=philipk@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.