if (*path1 != *path2)
break;
if (*path1 == '/')
- ret = i;
+ ret = i + 1;
path1++;
path2++;
i++;
const char *relto_suffix = can_relative_to + common_index;
const char *fname_suffix = can_fname + common_index;
+ /* skip over extraneous '/'. */
+ if (*relto_suffix == '/')
+ relto_suffix++;
+ if (*fname_suffix == '/')
+ fname_suffix++;
+
/* Replace remaining components of --relative-to with '..', to get
to a common directory. Then output the remainder of fname. */
if (*relto_suffix)
{
- ++relto_suffix;
printf ("%s", "..");
for (; *relto_suffix; ++relto_suffix)
{
printf ("%s", "/..");
}
- printf ("%s", fname_suffix);
+ if (*fname_suffix)
+ printf ("/%s", fname_suffix);
}
else
{
if (*fname_suffix)
- printf ("%s", ++fname_suffix);
+ printf ("%s", fname_suffix);
else
printf ("%c", '.');
}
# symlink resolution
this=$(realpath .)
-test "$(realpath $relative ldir2/..)" = "$this/dir1" || fail=1
-test "$(realpath -L $relative ldir2/..)" = "$this" || fail=1
-test "$(realpath -s $relative ldir2)" = "$this/ldir2" || fail=1
+test "$(realpath ldir2/..)" = "$this/dir1" || fail=1
+test "$(realpath -L ldir2/..)" = "$this" || fail=1
+test "$(realpath -s ldir2)" = "$this/ldir2" || fail=1
# relative string handling
test $(realpath -m --relative-to=prefix prefixed/1) = '../prefixed/1' || fail=1
test $(realpath -m --relative-to=prefixed prefix/1) = '../prefix/1' || fail=1
test $(realpath -m --relative-to=prefixed prefixed/1) = '1' || fail=1
+# Ensure no redundant trailing '/' present, as was the case in v8.15
+test $(realpath -sm --relative-to=/usr /) = '..' || fail=1
+# Ensure no redundant leading '../' present, as was the case in v8.15
+test $(realpath -sm --relative-to=/ /usr) = 'usr' || fail=1
+
Exit $fail