Merge pull request #31 from starkos/path-normalize-fix

Fix handling of "../../.." sequences in path.normalize()
This commit is contained in:
starkos 2015-04-09 12:20:11 -04:00
commit de47325370
2 changed files with 17 additions and 4 deletions

View File

@ -35,13 +35,11 @@ int path_normalize(lua_State* L)
if (ch == '.' && last == '.') {
ptr = dst - 3;
while (ptr >= buffer) {
if (*ptr != '/') {
--ptr;
}
else {
if (ptr[0] == '/' && ptr[1] != '.' && ptr[2] != '.') {
dst = ptr;
break;
}
--ptr;
}
if (ptr >= buffer) {
++src;

View File

@ -385,6 +385,21 @@
test.isequal("../../test", p)
end
function suite.normalize_Test4()
local p = path.normalize("../../../test/*.h")
test.isequal("../../../test/*.h", p)
end
function suite.normalize_trailingDots1()
local p = path.normalize("../game/test/..")
test.isequal("../game", p)
end
function suite.normalize_trailingDots2()
local p = path.normalize("../game/..")
test.isequal("..", p)
end
function suite.normalize()
test.isequal("d:/ProjectB/bin", path.normalize("d:/ProjectA/../ProjectB/bin"))
test.isequal("/ProjectB/bin", path.normalize("/ProjectA/../ProjectB/bin"))