diff --git a/CHANGES.txt b/CHANGES.txt index 4714da5e..b4eee7b7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -19,6 +19,7 @@ - Bug 2550759: pchheader option has wrong type - Bug 1900333: Parentheses in build path - Bug 2790865: SharedLib on OSX fixes (Ash Berlin) +- Bug 2790882: Trailing slash in path.getabsolute (Ash Berlin) ----- diff --git a/src/base/path.lua b/src/base/path.lua index 1ec79c33..829aac47 100644 --- a/src/base/path.lua +++ b/src/base/path.lua @@ -1,7 +1,7 @@ -- -- path.lua -- Path manipulation functions. --- Copyright (c) 2002-2008 Jason Perkins and the Premake project +-- Copyright (c) 2002-2009 Jason Perkins and the Premake project -- @@ -19,8 +19,8 @@ local result = iif (path.isabsolute(p), nil, os.getcwd()) -- split up the supplied relative path and tackle it bit by bit - for _,part in ipairs(p:explode("/", true)) do - if (part == "") then + for n, part in ipairs(p:explode("/", true)) do + if (part == "" and n == 1) then result = "/" elseif (part == "..") then result = path.getdirectory(result) @@ -29,6 +29,9 @@ end end + -- if I end up with a trailing slash remove it + result = iif(result:endswith("/"), result:sub(1, -2), result) + return result end diff --git a/tests/test_path.lua b/tests/test_path.lua index 44e8975b..7c05e8fb 100644 --- a/tests/test_path.lua +++ b/tests/test_path.lua @@ -25,6 +25,11 @@ test.isequal("/ProjectB/bin", path.getabsolute("/ProjectA/../ProjectB/bin")) end + function T.path.getabsolute_OnTrailingSlash() + local expected = path.translate(os.getcwd(), "/") .. "/a/b/c" + test.isequal(expected, path.getabsolute("a/b/c/")) + end + -- -- path.getbasename() tests