Skip to content

Commit 818369a

Browse files
committed
fix: Windows cmd.exe quoting — use ^\" for inner double quotes
cmd.exe interprets \" differently from the C runtime. Use ^" which cmd.exe treats as a literal double-quote without affecting its quote-state parser. Also use raw binary paths to avoid cmd.exe's special handling when the command starts with a double quote.
1 parent c30fa60 commit 818369a

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎src/xlings.cppm‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,12 @@ std::string shq(std::string_view s) {
321321
std::string out;
322322
out.reserve(s.size() + 2);
323323
#if defined(_WIN32)
324-
// cmd.exe uses double quotes; escape inner double quotes with backslash
324+
// Windows quoting for popen/system (goes through cmd.exe /c):
325+
// Use ^" to escape inner double quotes — cmd.exe treats ^" as a
326+
// literal double-quote character without affecting quote-state.
325327
out.push_back('"');
326328
for (char c : s) {
327-
if (c == '"') out += "\\\"";
329+
if (c == '"') out += "^\"";
328330
else out.push_back(c);
329331
}
330332
out.push_back('"');
@@ -663,8 +665,10 @@ int install_with_progress(const Env& env, std::string_view target,
663665
#if defined(_WIN32)
664666
_putenv_s("XLINGS_HOME", env.home.string().c_str());
665667
_putenv_s("XLINGS_PROJECT_DIR", "");
668+
// Use raw path (no quoting) to avoid cmd.exe double-quote parsing issues.
669+
// Wrap only the JSON arg in single-escaped quotes for the C runtime.
666670
auto cmd = std::format("{} interface install_packages --args {}",
667-
shq(env.binary.string()),
671+
env.binary.string(),
668672
shq(argsJson));
669673
#else
670674
auto cmd = std::format(

0 commit comments

Comments
 (0)