From 01afb1c8e997a4ce98bf107393101ea4cbb7e26b Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 10 Mar 2022 00:54:46 +0800 Subject: improve path.translate --- core/src/tbox/tbox | 2 +- core/src/xmake/path/translate.c | 10 +++++----- tests/modules/path/test.lua | 34 +++++++++++++++++----------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index 19a1e5652..1c62c6d02 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit 19a1e565216e9797c3c145d2db176d54c27991ca +Subproject commit 1c62c6d02cc76681e715dbfdb755901379942c22 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 -- cgit v1.3.1