Skip to content

Commit

Permalink
fixup! Add functionality for converting UNIX paths in arguments and e…
Browse files Browse the repository at this point in the history
…nvironment variables to Windows form for native Win32 applications.

When we fixed MSYS2's automatic Unix <-> Windows path conversion to
identify and skip Git-style `<rev>:<path>` arguments (and incidentally
also scp-style `<host>:<path>` 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 msys2#208

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho authored and ReinhardBiegelIntech committed Jul 2, 2024
1 parent 28d69fb commit 8ef78d5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion winsup/cygwin/msys2_path_conv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<rev>:<path>`, SCP's `<host>:<path>` pattern
* (which is not a path list but may naïvely look like one) on the one
* hand, and path lists starting with `/<path>`, `./<path>` or `../<path>`
* 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.
*/
Expand All @@ -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 <rev>:./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] == '/')
Expand Down

0 comments on commit 8ef78d5

Please sign in to comment.