Bug 2790882: Trailing slash in path.getabsolute (really a patch by Ash Berlin)

This commit is contained in:
starkos 2009-05-29 19:07:35 +00:00
parent d20ce6c62c
commit 11abed8bdd
3 changed files with 12 additions and 3 deletions

View File

@ -19,6 +19,7 @@
- Bug 2550759: pchheader option has wrong type - Bug 2550759: pchheader option has wrong type
- Bug 1900333: Parentheses in build path - Bug 1900333: Parentheses in build path
- Bug 2790865: SharedLib on OSX fixes (Ash Berlin) - Bug 2790865: SharedLib on OSX fixes (Ash Berlin)
- Bug 2790882: Trailing slash in path.getabsolute (Ash Berlin)
----- -----

View File

@ -1,7 +1,7 @@
-- --
-- path.lua -- path.lua
-- Path manipulation functions. -- 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()) local result = iif (path.isabsolute(p), nil, os.getcwd())
-- split up the supplied relative path and tackle it bit by bit -- split up the supplied relative path and tackle it bit by bit
for _,part in ipairs(p:explode("/", true)) do for n, part in ipairs(p:explode("/", true)) do
if (part == "") then if (part == "" and n == 1) then
result = "/" result = "/"
elseif (part == "..") then elseif (part == "..") then
result = path.getdirectory(result) result = path.getdirectory(result)
@ -29,6 +29,9 @@
end end
end end
-- if I end up with a trailing slash remove it
result = iif(result:endswith("/"), result:sub(1, -2), result)
return result return result
end end

View File

@ -25,6 +25,11 @@
test.isequal("/ProjectB/bin", path.getabsolute("/ProjectA/../ProjectB/bin")) test.isequal("/ProjectB/bin", path.getabsolute("/ProjectA/../ProjectB/bin"))
end 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 -- path.getbasename() tests