Skip to content

Commit e73cfd1

Browse files
committed
path_utils: Strip trailing path separators
Path may well end with a '/', e.g. URLs. So strip them away since otherwise mp_basename finds the wrong part of the given path. In case of the 'filename' property this simply results in it being set to the whole URL. But in case of the %f/%F screenshot-template specifiers it may result in a broken screenshot path, if %f occurs before the first '/'.
1 parent f37e372 commit e73cfd1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

misc/path_utils.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ char *mp_basename(const char *path)
4343
{
4444
char *s;
4545

46+
/* otherwise the check below finds the wrong index */
47+
mp_path_strip_trailing_separator((char *)path);
48+
4649
#if HAVE_DOS_PATHS
4750
if (!mp_is_url(bstr0(path))) {
4851
s = strrchr(path, '\\');
@@ -53,6 +56,7 @@ char *mp_basename(const char *path)
5356
path = s + 1;
5457
}
5558
#endif
59+
5660
s = strrchr(path, '/');
5761
return s ? s + 1 : (char *)path;
5862
}

0 commit comments

Comments
 (0)