]> git.e2factory.org Git - e2factory.git/commitdiff
Repair dirname and basename
authorTobias Ulmer <tu@emlix.com>
Wed, 9 Jan 2013 12:10:53 +0000 (13:10 +0100)
committerTobias Ulmer <tu@emlix.com>
Tue, 26 Feb 2013 18:07:13 +0000 (19:07 +0100)
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 <tu@emlix.com>
generic/e2lib.lua

index ca5200c9dc22cfc464ec8d8f1da0159702897002..98b2c19c0ab346e60e62ef7b942dada979fc91a2 100644 (file)
@@ -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