Skip to content

Commit 8df273b

Browse files
committed
fix: Windows shq — use bare \" without outer quotes
cmd.exe strips outer double quotes before the C runtime sees them. Using \" without outer quotes lets the MSVC C runtime argv parser correctly interpret escaped double quotes in JSON arguments.
1 parent 818369a commit 8df273b

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/xlings.cppm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,15 @@ std::string shq(std::string_view s) {
321321
std::string out;
322322
out.reserve(s.size() + 2);
323323
#if defined(_WIN32)
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.
327-
out.push_back('"');
324+
// Windows: popen/system go through cmd.exe /c. To avoid cmd.exe's
325+
// special quote-stripping when the command starts with ", we don't
326+
// wrap in outer quotes. Instead, escape inner " as \" which the
327+
// MSVC C runtime's argv parser understands.
328328
for (char c : s) {
329-
if (c == '"') out += "^\"";
329+
if (c == '"') out += "\\\"";
330330
else out.push_back(c);
331331
}
332-
out.push_back('"');
332+
return out;
333333
#else
334334
out.push_back('\'');
335335
for (char c : s) {

0 commit comments

Comments
 (0)