Repository navigation
Pass Unix commands to sh verbatim instead of escaping only quotes [patch] - #99
Merged
Merged
Conversation
…tch] NativeCommandExecutor built `-c "<command>"` by escaping only `"`, so backslashes already in the command combined with the inserted escapes under the MSVCRT splitting rules, and `echo "say \"hi\""` or `echo trailing\` failed with "Unterminated quoted string". On netcoreapp2.1+ the command now goes through ArgumentList, which needs no quoting. netstandard2.1 has no ArgumentList, so it quotes the command with a MSVCRT-correct escaper, tested by round-tripping arguments through ProcessStartInfo.Arguments. Fixes #54 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D7wytU6jsZ1cH3f6grCTz5
Keeps this change from touching the lines #53's fix edits, so the two PRs merge in either order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D7wytU6jsZ1cH3f6grCTz5
A lone backslash at the end of an `sh -c` script is up to the shell: dash keeps it, but the bash behind macOS's /bin/sh drops it as a line continuation, so the macOS leg failed although the command reached the shell verbatim. The case now ends in an even run of backslashes, which every shell reads the same way and which still fails against the old quotes-only escaping. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D7wytU6jsZ1cH3f6grCTz5
|
This was referenced Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #54
Problem
NativeCommandExecutor.CreateStartInfobuilt the Unix arguments as-c "<command>"and escaped only". .NET splitsArgumentsusing the MSVCRT rules, so backslashes already in the command combined with the inserted escapes, andshgot a mangled command. For example,echo "say \"hi\""andecho trailing\failed withUnterminated quoted string.Change
-cand the command are passed throughProcessStartInfo.ArgumentList, so nothing is quoted at all.ArgumentList: the command is wrapped by a new internalQuoteArgument, an MSVCRT-correct escaper. A run of backslashes before a quote is doubled and the quote escaped, and a trailing run is doubled.cmd.exe /c) is unchanged.Tests
NativeCommandExecutor_Passes_Backslashes_And_Quotes_To_The_Shell_Verbatimruns both repro commands from the issue, plus one with a run of backslashes before a quote, throughExecuteandExecuteAsync. It is limited to Linux/macOS.NativeCommandExecutor_QuoteArgument_Round_Trips_Through_Argumentscovers the netstandard path, which the net10.0 test project can't run directly. It passesQuoteArgumentoutput throughProcessStartInfo.Argumentstoprintf %sand checks that the child gets each argument back unchanged.Argumentsline restored, all 3 verbatim cases fail. With a quotes-only escaper in place ofQuoteArgument, 5 of the 9 round-trip cases fail.Essentials.CommandExecutors.Nativeis clean on all six targets, netstandard2.1 included.🤖 Generated with Claude Code
https://claude.ai/code/session_01D7wytU6jsZ1cH3f6grCTz5
Generated by Claude Code