From 50218a617b79f40482f12ef41e74bbefea002a17 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Wed, 9 Jan 2013 13:10:53 +0100 Subject: [PATCH] Repair dirname and basename basename and dirname must be able to handle paths ending in zero or more slashes. Concatenation of dir- and basename will otherwise go wrong in edge cases. previously: dirname(foo/bar/) -> foo/bar basename(foo/bar/) -> bar => foo/bar/bar now: dirname(foo/bar///) -> foo basename(foo/bar///) -> bar => foo/bar Signed-off-by: Tobias Ulmer --- generic/e2lib.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generic/e2lib.lua b/generic/e2lib.lua index ca5200c..98b2c19 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -565,7 +565,7 @@ end function e2lib.dirname(path) assert(type(path) == "string") - local s, e, dir = string.find(path, "^(.*)/[^/]*$") + local s, e, dir = string.find(path, "^(.*)/[^/]+[/]*$") if dir == "" then return "/" end @@ -580,7 +580,7 @@ end function e2lib.basename(path) assert(type(path) == "string") - local s, e, base = string.find(path, "^.*/([^/]+)[/]?$") + local s, e, base = string.find(path, "^.*/([^/]+)[/]*$") if not base then base = path end -- 2.39.5