From 5afdc084af66cea8c787d0961cf4eece7f8a88f2 Mon Sep 17 00:00:00 2001 From: WhitePeter Date: Thu, 6 Nov 2025 22:45:19 +0100 Subject: [PATCH 1/2] 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 '/'. --- misc/path_utils.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/misc/path_utils.c b/misc/path_utils.c index 766626e82dd25..037051923d106 100644 --- a/misc/path_utils.c +++ b/misc/path_utils.c @@ -43,6 +43,9 @@ char *mp_basename(const char *path) { char *s; + /* otherwise the check below finds the wrong index */ + mp_path_strip_trailing_separator((char *)path); + #if HAVE_DOS_PATHS if (!mp_is_url(bstr0(path))) { s = strrchr(path, '\\'); From 0e75fdc046cc58f285b4780b079e8ba1636883f7 Mon Sep 17 00:00:00 2001 From: WhitePeter Date: Fri, 7 Nov 2025 01:30:01 +0100 Subject: [PATCH 2/2] path_utils: strip all training separators It may be rare but multiple trailing slashes are perfectly valid. Keep stripping until all are gone. Previously this was a one shot operation. --- misc/path_utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/misc/path_utils.c b/misc/path_utils.c index 037051923d106..2d12149b5d504 100644 --- a/misc/path_utils.c +++ b/misc/path_utils.c @@ -57,7 +57,7 @@ char *mp_basename(const char *path) } #endif s = strrchr(path, '/'); - return s ? s + 1 : (char *)path; + return s && strlen(s) > 1 ? s + 1 : (char *)path; } struct bstr mp_dirname(const char *path) @@ -80,8 +80,8 @@ static const char mp_path_separators[] = "/"; // Mutates path and removes a trailing '/' (or '\' on Windows) void mp_path_strip_trailing_separator(char *path) { - size_t len = strlen(path); - if (len > 0 && strchr(mp_path_separators, path[len - 1])) + size_t len; + while ((len=strlen(path)) > 0 && strchr(mp_path_separators, path[len - 1])) path[len - 1] = '\0'; }