From 0e0185bfe31d3d226ffd382f2f91a153f2234cd9 Mon Sep 17 00:00:00 2001 From: Reinhard Biegel Date: Mon, 29 Apr 2024 10:01:29 +0200 Subject: [PATCH 1/5] pathconv: sync with msys2-runtime --- runtime/path_convert/src/path_conv.cpp | 38 ++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/runtime/path_convert/src/path_conv.cpp b/runtime/path_convert/src/path_conv.cpp index e5206f4..84712bc 100644 --- a/runtime/path_convert/src/path_conv.cpp +++ b/runtime/path_convert/src/path_conv.cpp @@ -269,7 +269,7 @@ void find_end_of_rooted_path(const char** from, const char** to, int* in_string) void sub_convert(const char** from, const char** to, char** dst, const char* dstend, int* in_string) { const char* copy_from = *from; path_type type = find_path_start_and_type(from, false, *to); - debug_printf("found type %d for path %s", type, copy_from); + debug_printf("found type %d for path %s\n", type, copy_from); if (type == POSIX_PATH_LIST) { find_end_of_posix_list(to, in_string); @@ -389,6 +389,40 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en return NONE; } + /* + * Discern between Git's `:`, SCP's `:` pattern + * (which is not a path list but may naïvely look like one) on the one + * hand, and path lists starting with `/`, `./` or `../` + * on the other hand. + */ + bool potential_path_list = *it == '/' || + (*it == '.' && + (it[1] == ':' || it[1] == '/' || + (it[1] == '.' && + (it[2] == ':' || it[2] == '/')))); + + /* + * Determine if assignment to an environment variable takes place (and + * skip Git/SCP handling if so) + */ + bool potential_command_scope_env = false; + if (isalpha(*it) || *it == '_' || *it == '-') { + ++it; + + if (it != end) { + if (*it == '-') + ++it; + + while (it != end && *it && (isalnum(*it) || *it == '_')) { + ++it; + } + + if (*it == '=') + potential_command_scope_env = true; + } + it = *src; + } + /* * Prevent Git's :file.txt and :/message syntax from beeing modified. */ @@ -414,7 +448,7 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en goto skip_p2w; // Leave Git's :./name syntax alone - if (it + 1 < end && it[1] == '.') { + if (!potential_path_list && !potential_command_scope_env && it + 1 < end && it[1] == '.') { if (it + 2 < end && it[2] == '/') goto skip_p2w; if (it + 3 < end && it[2] == '.' && it[3] == '/') From 7a2649d98b64d7df21bcaddd7ec7f81452b17506 Mon Sep 17 00:00:00 2001 From: Reinhard Biegel Date: Mon, 29 Apr 2024 10:17:49 +0200 Subject: [PATCH 2/5] pathconv: Update test cases for latest changes in git/scp exceptions --- runtime/path_convert/src/main.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/runtime/path_convert/src/main.cpp b/runtime/path_convert/src/main.cpp index bdc4fcb..2a359fe 100644 --- a/runtime/path_convert/src/main.cpp +++ b/runtime/path_convert/src/main.cpp @@ -177,10 +177,11 @@ static const test_data datas[] = { ,{"@/foo/bar@", "@" MSYSROOT2 "/foo/bar@", false} ,{"'@/foo/bar'", "'@/foo/bar'", false} ,{"///foo/bar", "//foo/bar", false} - ,{".:./", ".:./", false} - ,{"..:./", "..:./", false} - ,{"../:./", "../:./", false} - ,{"../aa/:./", "../aa/:./", false} + ,{".:./", ".;.\\", false} + ,{"..:./", "..;.\\", false} + ,{"../:./", "..\\;.\\", false} + ,{"../:./", "..\\;.\\", false} + ,{"../aa/:./", "..\\aa\\;.\\", false} ,{"../", "../", false} ,{"/foo/bar/", "" MSYSROOT2 "/foo/bar/", false} ,{"-MExtUtils::ParseXS=process_file", "-MExtUtils::ParseXS=process_file", false} @@ -236,6 +237,12 @@ static const test_data datas[] = { {".:/tmp/", ".;" MSYSROOT "\\tmp\\", false}, {"..:/tmp/", "..;" MSYSROOT "\\tmp\\", false}, {".:..:/tmp/", ".;..;" MSYSROOT "\\tmp\\", false}, + {"/this:./there", MSYSROOT "\\this;.\\there", false}, + {"..:.:./this:/there", "..;.;.\\this;" MSYSROOT "\\there", false}, + {"--dir=/this:./there", "--dir=" MSYSROOT "\\this;.\\there", false}, + {"--dir=./this:./there", "--dir=.\\this;.\\there", false}, + {"WEBINPUTS=.:../../../texk/web2c", "WEBINPUTS=.;..\\..\\..\\texk\\web2c", false}, + {".:../../../texk/web2c", ".;..\\..\\..\\texk\\web2c", false}, {"/:/tmp/", MSYSROOT "\\;" MSYSROOT "\\tmp\\", false}, {0, 0, false} }; From 5c06db0022011e3c5f635982de35478764467582 Mon Sep 17 00:00:00 2001 From: Reinhard Biegel Date: Mon, 29 Apr 2024 10:24:37 +0200 Subject: [PATCH 3/5] pathconv: Fix ifdef typo --- runtime/path_convert/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/path_convert/src/main.cpp b/runtime/path_convert/src/main.cpp index 2a359fe..8b1fe59 100644 --- a/runtime/path_convert/src/main.cpp +++ b/runtime/path_convert/src/main.cpp @@ -21,7 +21,7 @@ typedef struct test_data_t { #error "Need to define both MSYSROOT and MSYSROOT2, or neither" #endif #else -#ifdef MSYSROOT +#ifdef MSYSROOT2 #error "Need to define both MSYSROOT and MSYSROOT2, or neither" #endif #if defined(__MSYS__) && defined(__LP64__) From 49948891d4091dd09d35e7f90b477313dfd6ea30 Mon Sep 17 00:00:00 2001 From: Reinhard Biegel Date: Mon, 29 Apr 2024 10:27:25 +0200 Subject: [PATCH 4/5] pathconv: Improve readability for testsuite outputs --- runtime/path_convert/src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/path_convert/src/main.cpp b/runtime/path_convert/src/main.cpp index 8b1fe59..8b29b46 100644 --- a/runtime/path_convert/src/main.cpp +++ b/runtime/path_convert/src/main.cpp @@ -287,6 +287,7 @@ int main() { int passed = 0; int total = 0; for ( const test_data *it = &datas[0]; it && it->src; ++it ) { + printf("---\n"); total += 1; const char *path = it->src; const size_t blen = strlen(it->dst)*2 + 10; From 6aba9cb1c269bd2cc12c108c2f80eeb02776cfb0 Mon Sep 17 00:00:00 2001 From: Reinhard Biegel Date: Tue, 2 Jul 2024 09:56:25 +0200 Subject: [PATCH 5/5] pathconv: sync with msys2-runtime Suggested-by: Richard Copley --- runtime/path_convert/src/path_conv.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/path_convert/src/path_conv.cpp b/runtime/path_convert/src/path_conv.cpp index 84712bc..7169ab6 100644 --- a/runtime/path_convert/src/path_conv.cpp +++ b/runtime/path_convert/src/path_conv.cpp @@ -391,15 +391,15 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en /* * Discern between Git's `:`, SCP's `:` pattern - * (which is not a path list but may naïvely look like one) on the one + * (which is not a path list but may naively look like one) on the one * hand, and path lists starting with `/`, `./` or `../` * on the other hand. */ bool potential_path_list = *it == '/' || - (*it == '.' && - (it[1] == ':' || it[1] == '/' || - (it[1] == '.' && - (it[2] == ':' || it[2] == '/')))); + (*it == '.' && + (it + 1 == end || it[1] == '\0' || it[1] == ':' || it[1] == '/' || + (it[1] == '.' && + (it + 2 == end || it[2] == '\0' || it[2] == ':' || it[2] == '/')))); /* * Determine if assignment to an environment variable takes place (and