Skip to content

Commit 9677111

Browse files
fix(client-runtime): leave statement terminators out of PowerShell call-operator labels (#45476)
Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
1 parent ce39d46 commit 9677111

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎packages/client-runtime/src/work-log/commandLabel.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ describe("commandProgramName", () => {
2323
["pwsh -NoProfile -Command Start-Process -FilePath git", "git"],
2424
['powershell -Command "git;pwd" > out.txt', "git"],
2525
['cmd /c "git&&npm test" 2>&1', "git"],
26+
["pwsh -Command '& Get-Date; Get-Location'", "Get-Date"],
27+
["pwsh -Command '& git|Out-Null'", "git"],
28+
["pwsh -Command '& “./build;release.ps1”'", "build;release.ps1”"],
2629
])("unwraps shell scripts without executing them: %s", (command, program) => {
2730
expect(commandProgramName(command)).toBe(program);
2831
});

‎packages/client-runtime/src/work-log/commandLabel.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,13 @@ function staticProgramName(value: string): string | null {
933933
function leadingPowerShellLiteral(command: string): string | null {
934934
const input = command.trimStart();
935935
const quote = input[0];
936-
if (quote !== '"' && quote !== "'") return staticProgramName(input.match(/^\S+/u)?.[0] ?? "");
936+
if (quote !== '"' && quote !== "'") {
937+
const token = input.match(/^\S+/u)?.[0] ?? "";
938+
// Quotes (including PowerShell's typographic ones), escapes and subexpressions
939+
// can hide a delimiter, so only cut at a delimiter that comes before any of them.
940+
const stop = token.match(/[;|&'"`$({‘’‚‛“”„]/u);
941+
return staticProgramName(stop && /[;|&]/u.test(stop[0]) ? token.slice(0, stop.index) : token);
942+
}
937943

938944
let value = "";
939945
for (let index = 1; index < input.length; index += 1) {

0 commit comments

Comments
 (0)