Merge pull request #31 from starkos/path-normalize-fix
Fix handling of "../../.." sequences in path.normalize()
This commit is contained in:
commit
de47325370
@ -35,13 +35,11 @@ int path_normalize(lua_State* L)
|
|||||||
if (ch == '.' && last == '.') {
|
if (ch == '.' && last == '.') {
|
||||||
ptr = dst - 3;
|
ptr = dst - 3;
|
||||||
while (ptr >= buffer) {
|
while (ptr >= buffer) {
|
||||||
if (*ptr != '/') {
|
if (ptr[0] == '/' && ptr[1] != '.' && ptr[2] != '.') {
|
||||||
--ptr;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
dst = ptr;
|
dst = ptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
--ptr;
|
||||||
}
|
}
|
||||||
if (ptr >= buffer) {
|
if (ptr >= buffer) {
|
||||||
++src;
|
++src;
|
||||||
|
@ -385,6 +385,21 @@
|
|||||||
test.isequal("../../test", p)
|
test.isequal("../../test", p)
|
||||||
end
|
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()
|
function suite.normalize()
|
||||||
test.isequal("d:/ProjectB/bin", path.normalize("d:/ProjectA/../ProjectB/bin"))
|
test.isequal("d:/ProjectB/bin", path.normalize("d:/ProjectA/../ProjectB/bin"))
|
||||||
test.isequal("/ProjectB/bin", path.normalize("/ProjectA/../ProjectB/bin"))
|
test.isequal("/ProjectB/bin", path.normalize("/ProjectA/../ProjectB/bin"))
|
||||||
|
Loading…
Reference in New Issue
Block a user