aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-08-30 17:50:08 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-08-30 17:50:08 +0200
commita8036b9c22e5b083bd938dee444e431c5b97a0bf (patch)
treef32a084b704eebe1960bfead365747a69677809b
parentacde650d74c2d7f41328fa94dd130ca144fd5487 (diff)
Quote []() in Windows arguments to help Cygwin/MSYS2
-rw-r--r--libbutl/process.cxx13
1 files changed, 9 insertions, 4 deletions
diff --git a/libbutl/process.cxx b/libbutl/process.cxx
index 73cc8a6..f6433fb 100644
--- a/libbutl/process.cxx
+++ b/libbutl/process.cxx
@@ -1326,8 +1326,13 @@ namespace butl
// may add a flag to disable all quoting since the user may need to quote
// some arguments but not others).
//
- bool q (*a == '\0' ||
- (bat ? strpbrk (a, " =,;") : strchr (a, ' ')) != nullptr);
+ // While `()` and `[]` are not special characters, some "subsystems"
+ // (e.g., Cygwin/MSYS2) try to interpret them in certain contexts (e.g.,
+ // relative paths). So we quote them as well (over-quoting seems to be
+ // harmless according to the "Parsing C Command-Line Arguments" MSDN
+ // article).
+ //
+ bool q (*a == '\0' || strpbrk (a, bat ? " =,;" : " ()[]") != nullptr);
if (!q && strchr (a, '"') == nullptr)
return a;
@@ -1338,8 +1343,8 @@ namespace butl
s += '"';
// Note that backslashes don't need escaping, unless they immediately
- // precede the double quote (see `Parsing C Command-Line Arguments` MSDN
- // article for more details). For example:
+ // precede the double quote (see "Parsing C Command-Line Arguments" MSDN
+ // article for details). For example:
//
// -DPATH="C:\\foo\\" -> -DPATH=\"C:\\foo\\\\\"
// -DPATH=C:\foo bar\ -> "-DPATH=C:\foo bar\\"