From 0ff6ce64d91ed2641d30e70782a50ba0fc638406 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 17 Apr 2024 10:21:29 +0200 Subject: [PATCH] fixup! Add functionality for converting UNIX paths in arguments and environment variables to Windows form for native Win32 applications. When we fixed MSYS2's automatic Unix <-> Windows path conversion to identify and skip Git-style `:` arguments (and incidentally also scp-style `:` ones), we assumed that path lists containing relative paths would be a rare scenario. My, was this assumption wrong! Let's add another heuristic that detects absolute paths at the beginning of path lists, and relative ones starting with either `./` or `../`, neither of which match those Git-style nor scp-style arguments, and then prevent the detection of the latter style from kicking in. This addresses https://github.com/msys2/msys2-runtime/issues/208 Signed-off-by: Johannes Schindelin --- winsup/cygwin/msys2_path_conv.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index 4c0cc82cf2..0902dff3fd 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -358,6 +358,18 @@ 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] == '/')))); + /* * Prevent Git's :file.txt and :/message syntax from beeing modified. */ @@ -383,7 +395,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 && it + 1 < end && it[1] == '.') { if (it + 2 < end && it[2] == '/') goto skip_p2w; if (it + 3 < end && it[2] == '.' && it[3] == '/')