From f15004d46a08e29d2555ecd2bd15793389b426fb Mon Sep 17 00:00:00 2001 From: andy5995 Date: Thu, 28 Nov 2024 00:56:14 -0600 Subject: [PATCH 1/6] tests: Add debugging output to resolver-paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I don't know much about your preferences or how you like to configure tests, but I took a guess and made a few quick changes. With the changes in this PR, when `meson test` is run with `-v`, one can see more: ``` stderr: ╭ /hello world/banana/ ├ quick-js/././ww/aee/ ├> /hello world/banana/quick-js/ww/aee ╰>> /hello world/banana/quick-js/ww/aee/ ╭ /hello world/banana/ ├ quick-js/././ww/aee/ ├> /hello world/banana/quick-js/ww/ ╰>> /hello world/banana/quick-js/ww/aee/ ╭ /hello world/banana/ ├ quick-js/././ww/aee ├> /hello world/banana/quick-js/ww/ ╰>> /hello world/banana/quick-js/ww/ ╭ /hello world/banana/ ├ ../../quick-js/ww/a ├> /quick-js/ww/a ╰>> /quick-js/ww/a ╭ /hello world/banana/ ├ ./../.././quick-js/ww/a ├> /quick-js/ww/a ╰>> /quick-js/ww/a ╭ /hello world/banana/ ├ ../../quick-js/ww/a ├> ╰>> ╭ /hello world/banana/ ├ ./../.././quick-js/ww/a ├> ╰>> ╭ /hello world/banana/ ├ quick-js/../quick-js/ww/a ├> /hello world/banana/quick-js/ww/a ╰>> /hello world/banana/ww/a ╭ /hello world/banana/ ├ quick-js/./.././ww/a ├> /hello world/banana/ww/a ╰>> /hello world/banana/ww/a ╭ /a/ ├ b../ ├> /a/ ╰>> /a/b../ ret = 4 test_resolver-paths: ../test/marginal/resolver-paths.cpp:33: int main(): Assertion `ret=0' failed. ``` --- .github/workflows/build.yml | 1 + src/utils/paths.cpp | 6 +++--- test/marginal/resolver-paths.cpp | 15 ++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e78ce653..cde05c24 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -115,6 +115,7 @@ jobs: # Unclear fix to be investigated rm subprojects/libtcc/VERSION meson compile -C build/ vs:executable + meson test test_resolver-paths -C build -v - name: Archive production artifacts uses: actions/upload-artifact@v4 with: diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index 2c2f9a21..612053fe 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -50,8 +50,8 @@ std::pair resolve_path::normalizer(const char *parent, const j++; continue; } - else if(child[j]=='/'){ - j++; + else if(child[j]=='/' && j!=child_len-1){ + j++; } else{ ret[ptr]=child[j]; @@ -157,4 +157,4 @@ std::pair resolve_path::operator()(fro return {reason_t::MALFORMED,{rpath_type_t::NONE, ""}}; } -} \ No newline at end of file +} diff --git a/test/marginal/resolver-paths.cpp b/test/marginal/resolver-paths.cpp index 2dbf2236..6e6e42f1 100644 --- a/test/marginal/resolver-paths.cpp +++ b/test/marginal/resolver-paths.cpp @@ -6,10 +6,10 @@ using namespace vs; int test_normalizer(const char* expected, const char* parent, const char* child, bool allow_exit, bool base_dir){ auto tmp = resolve_path::normalizer(parent,child,allow_exit,base_dir); - std::cout<<"╭ "< "< "<> "< "< "< "<> "< Date: Mon, 9 Dec 2024 04:40:56 -0600 Subject: [PATCH 2/6] Fix the last failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ╭ /a/ ├ b../ ├> /a/b../ ╰>> /a/b../ --- src/utils/paths.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index 612053fe..dc2c580e 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -30,11 +30,20 @@ std::pair resolve_path::normalizer(const char *parent, const memset(ret+parent_len,0,child_len+1); memcpy(ret,parent,parent_len); int ptr = parent_len; - + for(int j=0; j 0) { + if (child[j-1] != '/') { + uint8_t i = 0; + for(;i<=sizeof "../";i++) { + ret[ptr++] = child[j++]; + } + continue; + } + } ptr-=2; for(;ret[ptr]!='/';ptr--); j+=3; From fe08deb518e65dd65f584912b3f3f1ba26a5bd64 Mon Sep 17 00:00:00 2001 From: andy5995 Date: Mon, 9 Dec 2024 04:42:43 -0600 Subject: [PATCH 3/6] Execute tests in CI --- .github/workflows/build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cde05c24..349c3f04 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,6 +75,7 @@ jobs: bun run codegen bun run meson-setup.clang-release meson compile -C build/ vs:executable + bun run test - name: Archive production artifacts uses: actions/upload-artifact@v4 with: @@ -115,7 +116,7 @@ jobs: # Unclear fix to be investigated rm subprojects/libtcc/VERSION meson compile -C build/ vs:executable - meson test test_resolver-paths -C build -v + bun run test - name: Archive production artifacts uses: actions/upload-artifact@v4 with: From 63b300274a0c0d0d42beaa1e4d251ff0167eab20 Mon Sep 17 00:00:00 2001 From: andy5995 Date: Mon, 9 Dec 2024 04:45:29 -0600 Subject: [PATCH 4/6] Remove unused code block/condition --- src/utils/paths.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index dc2c580e..0a3996af 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -55,10 +55,6 @@ std::pair resolve_path::normalizer(const char *parent, const j+=2; //Just skip this. continue; } - else if(child[j]=='/' && child[j+1]=='/'){ - j++; - continue; - } else if(child[j]=='/' && j!=child_len-1){ j++; } From 3ea69a0889d784ecc98d6f9aad20093d1ecb6c0a Mon Sep 17 00:00:00 2001 From: andy5995 Date: Mon, 9 Dec 2024 04:46:28 -0600 Subject: [PATCH 5/6] remove leading whitespace --- src/utils/paths.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index 0a3996af..af822b55 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -56,7 +56,7 @@ std::pair resolve_path::normalizer(const char *parent, const continue; } else if(child[j]=='/' && j!=child_len-1){ - j++; + j++; } else{ ret[ptr]=child[j]; From 3f811e0f58ca4e76cdd8fa24031c973affc850e0 Mon Sep 17 00:00:00 2001 From: andy5995 Date: Mon, 9 Dec 2024 08:57:17 -0600 Subject: [PATCH 6/6] Remove unneeded block (merged with prior condition) --- src/utils/paths.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index af822b55..4b51e70f 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -57,6 +57,8 @@ std::pair resolve_path::normalizer(const char *parent, const } else if(child[j]=='/' && j!=child_len-1){ j++; + ret[ptr]='/'; + ptr++; } else{ ret[ptr]=child[j]; @@ -64,11 +66,6 @@ std::pair resolve_path::normalizer(const char *parent, const j++; continue; } - - if(j!=child_len){ - ret[ptr]='/'; - ptr++; - } } //TODO: Stress test for potential unsafety