summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-03-10 00:54:46 +0800
committerruki <[email protected]>2022-03-10 00:54:46 +0800
commit01afb1c8e997a4ce98bf107393101ea4cbb7e26b (patch)
tree54181e7e2848c716db9fe5a92607ab5f40b6d352
parent64db618a134e8a474f4d785ee47cf04723f782ef (diff)
improve path.translate
m---------core/src/tbox/tbox0
-rw-r--r--core/src/xmake/path/translate.c10
-rw-r--r--tests/modules/path/test.lua34
3 files changed, 22 insertions, 22 deletions
diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox
-Subproject 19a1e565216e9797c3c145d2db176d54c27991c
+Subproject 1c62c6d02cc76681e715dbfdb755901379942c2
diff --git a/core/src/xmake/path/translate.c b/core/src/xmake/path/translate.c
index 87059c85c..3074c0b2a 100644
--- a/core/src/xmake/path/translate.c
+++ b/core/src/xmake/path/translate.c
@@ -43,20 +43,20 @@ tb_int_t xm_path_translate(lua_State* lua)
tb_char_t const* path = luaL_checklstring(lua, 1, &path_size);
tb_check_return_val(path, 0);
- // get the option argument, e.g. {reduce_dot2 = true}
- tb_bool_t reduce_dot2 = tb_false;
+ // get the option argument, e.g. {normalize = true}
+ tb_bool_t normalize = tb_false;
if (lua_istable(lua, 2))
{
- lua_pushstring(lua, "reduce_dot2");
+ lua_pushstring(lua, "normalize");
lua_gettable(lua, 2);
if (lua_toboolean(lua, -1))
- reduce_dot2 = tb_true;
+ normalize = tb_true;
lua_pop(lua, 1);
}
// do path:translate()
tb_char_t data[TB_PATH_MAXN];
- tb_size_t size = tb_path_translate_to(path, (tb_size_t)path_size, data, sizeof(data), reduce_dot2);
+ tb_size_t size = tb_path_translate_to(path, (tb_size_t)path_size, data, sizeof(data), normalize);
if (size) lua_pushlstring(lua, data, (size_t)size);
else lua_pushnil(lua);
return 1;
diff --git a/tests/modules/path/test.lua b/tests/modules/path/test.lua
index 8954e64a3..3df399b65 100644
--- a/tests/modules/path/test.lua
+++ b/tests/modules/path/test.lua
@@ -90,34 +90,34 @@ function test_translate(t)
t:are_equal(path.translate(""), nil)
t:are_equal(path.translate("."), ".")
t:are_equal(path.translate(".."), "..")
- t:are_equal(path.translate("././."), ".")
- t:are_equal(path.translate("../foo/..", {reduce_dot2 = true}), "..")
- t:are_equal(path.translate("../foo/bar/../..", {reduce_dot2 = true}), "..")
+ t:are_equal(path.translate("././.", {normalize = true}), ".")
+ t:are_equal(path.translate("../foo/..", {normalize = true}), "..")
+ t:are_equal(path.translate("../foo/bar/../..", {normalize = true}), "..")
if is_host("windows") then
t:are_equal(path.translate("c:"), "c:")
t:are_equal(path.translate("c:\\"), "c:")
- t:are_equal(path.translate("c:\\foo\\.\\.\\"), "c:\\foo")
t:are_equal(path.translate("c:\\foo\\\\\\"), "c:\\foo")
t:are_equal(path.translate("c:\\foo\\..\\.."), "c:\\foo\\..\\..")
- t:are_equal(path.translate("c:\\foo\\bar\\.\\..\\xyz", {reduce_dot2 = true}), "c:\\foo\\xyz")
- t:are_equal(path.translate("c:\\foo\\.\\..", {reduce_dot2 = true}), "c:")
- t:are_equal(path.translate("../..", {reduce_dot2 = true}), "..\\..")
- t:are_equal(path.translate("../foo/bar/..", {reduce_dot2 = true}), "..\\foo")
- t:are_equal(path.translate("../foo/bar/../../..", {reduce_dot2 = true}), "..\\..")
+ t:are_equal(path.translate("c:\\foo\\.\\.\\", {normalize = true}), "c:\\foo")
+ t:are_equal(path.translate("c:\\foo\\bar\\.\\..\\xyz", {normalize = true}), "c:\\foo\\xyz")
+ t:are_equal(path.translate("c:\\foo\\.\\..", {normalize = true}), "c:")
+ t:are_equal(path.translate("../..", {normalize = true}), "..\\..")
+ t:are_equal(path.translate("../foo/bar/..", {normalize = true}), "..\\foo")
+ t:are_equal(path.translate("../foo/bar/../../..", {normalize = true}), "..\\..")
else
t:are_equal(path.translate("/"), "/");
t:are_equal(path.translate("////"), "/");
- t:are_equal(path.translate("/./././"), "/");
- t:are_equal(path.translate("/foo/././"), "/foo");
t:are_equal(path.translate("/foo//////"), "/foo");
t:are_equal(path.translate("/foo/../.."), "/foo/../..");
t:are_equal(path.translate("/foo/../../"), "/foo/../..");
- t:are_equal(path.translate("/foo/bar/.//..//xyz", {reduce_dot2 = true}), "/foo/xyz");
- t:are_equal(path.translate("/foo/../..", {reduce_dot2 = true}), "/");
- t:are_equal(path.translate("/foo/bar../..", {reduce_dot2 = true}), "/foo");
- t:are_equal(path.translate("../..", {reduce_dot2 = true}), "../..");
- t:are_equal(path.translate("../foo/bar/..", {reduce_dot2 = true}), "../foo");
- t:are_equal(path.translate("../foo/bar/../../..", {reduce_dot2 = true}), "../..");
+ t:are_equal(path.translate("/foo/././", {normalize = true}), "/foo");
+ t:are_equal(path.translate("/./././", {normalize = true}), "/");
+ t:are_equal(path.translate("/foo/bar/.//..//xyz", {normalize = true}), "/foo/xyz");
+ t:are_equal(path.translate("/foo/../..", {normalize = true}), "/");
+ t:are_equal(path.translate("/foo/bar../..", {normalize = true}), "/foo");
+ t:are_equal(path.translate("../..", {normalize = true}), "../..");
+ t:are_equal(path.translate("../foo/bar/..", {normalize = true}), "../foo");
+ t:are_equal(path.translate("../foo/bar/../../..", {normalize = true}), "../..");
end
end