Repository navigation
[bugfix] Pass PowerShell inline commands via -EncodedCommand so quotes survive on Windows (#3907) - #4491
Open
IT-Althusser wants to merge 1 commit into
Open
[bugfix] Pass PowerShell inline commands via -EncodedCommand so quotes survive on Windows (#3907)#4491IT-Althusser wants to merge 1 commit into
IT-Althusser wants to merge 1 commit into
Conversation
IT-Althusser
force-pushed
the
fix/powershell-command-quoting
branch
from
October 24, 2026 03:38
b05a385 to
0fe98ef
Compare
… on Windows (apache#3907) -EncodedCommand passes the script as Base64/UTF-16LE, so the Windows command-line parser cannot strip quotes, pipes or backtick escapes. PowerShell serializes progress/information/error records as CLIXML on a redirected stderr; normalize them so failure messages stay readable.
IT-Althusser
force-pushed
the
fix/powershell-command-quoting
branch
from
October 24, 2026 03:47
0fe98ef to
6ace2c2
Compare
This branch has not been deployed
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.
What's changed
PowerShell inline commands are now passed to
powershell.exevia-EncodedCommand(Base64 of UTF-16LE) instead of-Command, and the CLIXML stderr that-EncodedCommandproduces is normalized back to plain error text.Why
On Windows,
ProcessBuilderwraps an argument in double quotes but does not escape embedded quotes, so a script such asWrite-Output "x y"reaches the child as"Write-Output "x y"".powershell.exe -Commandre-tokenizes that raw command line, so quoting-heavy monitoring commands (nested quotes, pipes, backtick escapes — e.g. the one in #3907) arrive mangled, fail to parse, and the collector only reportsScript response data is null. Reproduced on Windows 11 against the exact command shape from the issue:Base64-encoded scripts contain no characters the command-line parser can alter, so the script reaches PowerShell verbatim. The payload is UTF-16LE, which also removes the input-encoding ambiguity for non-ASCII scripts.
-EncodedCommandis supported by Windows PowerShell 5.1, the executable this code path invokes.-EncodedCommandalso makes PowerShell serialize progress/information/error records to a redirected stderr as a CLIXML document. Left as-is, every collection would log roughly 0.4 KB of XML, failure messages would show XML instead of the PowerShell error, and the empty-outputoneRowpath would stop working because stderr is never empty.ScriptCollectImplnow keeps only the<S S="Error">entries, so logs and failure messages stay readable and the empty-output behavior is preserved.How checked
@EnabledOnOs(OS.WINDOWS): a quoting-heavyWrite-Output, a pipe + backtick-escape command mirroring [BUG] 使用windows命令监控采集问题 #3907, and a failing command whose message must not contain XML. They are skipped on the Linux CI becausepowershell.exedoes not exist there.mvn -pl hertzbeat-collector/hertzbeat-collector-basic -am test -Dtest='ScriptCollectImplTest#preCheck+supportProtocol+normalizePowerShellStderrKeepsErrorsAndDropsProgress+normalizePowerShellStderrLeavesPlainTextUntouched+collectPowershellWithQuotes+collectPowershellPipelineWithBacktickEscape+failingPowerShellCommandReportsReadableError' -Dsurefire.failIfNoSpecifiedTests=false→ 7 tests, 0 failures.collect()bash case fails on this machine becausebashresolves to the WSL stub without a distro. That case is green on the upstream Linux CI and is unrelated to this diff.bash/cmd/-Filepaths are untouched.Note: Base64/UTF-16LE expands the script roughly 2.7x, so inline scripts must stay well below the Windows 32,767-character command-line limit (about 12k characters); longer scripts can still be deployed through
scriptPath/-File.Closes #3907
Checklist
Add or update API