Merge pull request #104 from Blizzard/normalize-fix
filter out /./ in path.join and path.normalize
This commit is contained in:
commit
0280d44efd
@ -28,6 +28,12 @@ int path_join(lua_State* L)
|
||||
part = luaL_checkstring(L, i);
|
||||
len = strlen(part);
|
||||
|
||||
/* remove leading "./" */
|
||||
while (strncmp(part, "./", 2) == 0) {
|
||||
part += 2;
|
||||
len -= 2;
|
||||
}
|
||||
|
||||
/* remove trailing slashes */
|
||||
while (len > 1 && part[len - 1] == '/') {
|
||||
--len;
|
||||
|
@ -47,6 +47,15 @@ int path_normalize(lua_State* L)
|
||||
}
|
||||
}
|
||||
|
||||
/* filter out /./ */
|
||||
if (ch == '/' && last == '.') {
|
||||
ptr = dst - 2;
|
||||
if (ptr >= buffer && ptr[0] == '/') {
|
||||
dst = ptr;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* add to the result, filtering out duplicate slashes */
|
||||
if (ch != '/' || last != '/') {
|
||||
*(dst++) = ch;
|
||||
|
@ -275,6 +275,10 @@
|
||||
test.isequal("foo", path.join("p1/p2/p3", "../../../foo"))
|
||||
end
|
||||
|
||||
function suite.join_ignoreLeadingDots()
|
||||
test.isequal("p1/p2/foo", path.join("p1/p2", "././foo"))
|
||||
end
|
||||
|
||||
function suite.join_OnUptoParentOfBase()
|
||||
test.isequal("../../p1", path.join("p1/p2/p3/p4/p5/p6/p7/", "../../../../../../../../../p1"))
|
||||
end
|
||||
@ -429,7 +433,12 @@
|
||||
test.isequal("..", p)
|
||||
end
|
||||
|
||||
function suite.normalize_singleDot()
|
||||
local p = path.normalize("../../p1/p2/p3/p4/./a.pb.cc")
|
||||
test.isequal("../../p1/p2/p3/p4/a.pb.cc", 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"))
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user