normalize_path: Squash leading slashes even without allow_leading

This currently changes builtin realpath with the "-s" option:

    builtin realpath -s ///tmp

previously would print "///tmp", now it prints "/tmp".

The only thing "allow_leading_double_slashes" does is allow *two*
slashes.

This is important for `path match`, to be introduced in #8265.
This commit is contained in:
Fabian Homborg
2021-09-09 17:22:14 +02:00
parent 1ff6160058
commit a78d9d8e9a
2 changed files with 15 additions and 4 deletions

View File

@@ -95,6 +95,15 @@ else
echo "failure nonexistent-file-relative-to-a-symlink: $real_path != $expected_real_path" >&2
end
# We remove leading slashes even with "-s".
# This is how GNU realpath -s behaves, and also e.g.
# how bash normalizes its $PWD.
builtin realpath -s ///bin
# CHECK: /bin
builtin realpath -s //bin
# CHECK: /bin
# A path with two symlinks, first to a directory, second to a file, is correctly resolved.
ln -fs fish $XDG_DATA_HOME/fish-symlink2
touch $XDG_DATA_HOME/fish/real_file