From b068b2ea010d16a6d1b442720ff526ce23b23921 Mon Sep 17 00:00:00 2001 From: Nestor Fedyk Date: Fri, 19 Sep 2025 11:09:05 -0400 Subject: [PATCH 1/3] Fixed bleeding value of the command argument into the next empty valued argument --- psCommandService.js | 2 +- test/unit.js | 72 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/psCommandService.js b/psCommandService.js index e195368..12cd4ef 100644 --- a/psCommandService.js +++ b/psCommandService.js @@ -304,7 +304,7 @@ PSCommandService.prototype._generateCommand = function(commandConfig, argument2V var passedArgValue = passedArgValues[i]; - var valueToSet; + var valueToSet = ""; if (passedArgValue && passedArgValue != 'undefined') { valueToSet = passedArgValue; diff --git a/test/unit.js b/test/unit.js index e274f79..c3a1373 100644 --- a/test/unit.js +++ b/test/unit.js @@ -84,6 +84,29 @@ const commandRegistry = { type: "text", }, }, + setContent: { + command: "Set-Content {{{arguments}}}", + arguments: { + 'Path': {}, + 'Value': {}, + 'Filter': {}, + }, + }, + getContent: { + command: "Get-Content {{{arguments}}}", + arguments: { + 'Path': {}, + }, + return: { + type: "text", + }, + }, + removeItem: { + command: "Remove-Item {{{arguments}}}", + arguments: { + 'Path': {}, + }, + }, }; @@ -580,4 +603,53 @@ describe("test PSCommandService w/ o365CommandRegistry", function () { throw e; } }); + it("Should test value bleading", async function () { + this.timeout(10000); + const statefulProcessCommandProxy = new StatefulProcessCommandProxy({ + name: "Powershell pool", + max: 1, + min: 1, + idleTimeoutMS: 30000, + + logFunction: logFunction, + processCommand: "pwsh", + processArgs: ["-Command", "-"], + processRetainMaxCmdHistory: 30, + processCwd: null, + processEnvMap: null, + processUid: null, + processGid: null, + initCommands: initCommands, + validateFunction: (processProxy) => processProxy.isValid(), + }); + + const psCommandService = new PSCommandService( + statefulProcessCommandProxy, + commandRegistry, + myLogFunction + ); + try { + const newResult = await psCommandService.execute("setContent", { + Path: "./test.txt", + Value: "Test", + Filter: "" + }); + assert.equal(newResult.command.trim(), "Set-Content -Path './test.txt' -Value 'Test'"); + assert.equal(newResult.stderr, ""); + const getResult = await psCommandService.execute("getContent", { + Path: "./test.txt", + }); + assert.equal(getResult.stderr, ""); + assert.equal(getResult.stdout, "Test"); + } catch (e) { + assert.fail(e); + } finally { + await psCommandService.execute("removeItem", { + Path: "./test.txt" + }); + setTimeout(() => { + statefulProcessCommandProxy.shutdown(); + }, 5000); + } + }); }); From 8681dd6e62d00ea3f80bc340799815262a841bfc Mon Sep 17 00:00:00 2001 From: Nestor Fedyk Date: Fri, 19 Sep 2025 11:23:12 -0400 Subject: [PATCH 2/3] Update test/unit.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- test/unit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit.js b/test/unit.js index c3a1373..4358d05 100644 --- a/test/unit.js +++ b/test/unit.js @@ -603,7 +603,7 @@ describe("test PSCommandService w/ o365CommandRegistry", function () { throw e; } }); - it("Should test value bleading", async function () { + it("Should test value bleeding", async function () { this.timeout(10000); const statefulProcessCommandProxy = new StatefulProcessCommandProxy({ name: "Powershell pool", From a8d802b1579a9a87db591e7af80c206a2a5ca8fe Mon Sep 17 00:00:00 2001 From: Nestor Fedyk Date: Fri, 19 Sep 2025 11:23:27 -0400 Subject: [PATCH 3/3] Update test/unit.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- test/unit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit.js b/test/unit.js index 4358d05..9638f9f 100644 --- a/test/unit.js +++ b/test/unit.js @@ -645,7 +645,7 @@ describe("test PSCommandService w/ o365CommandRegistry", function () { assert.fail(e); } finally { await psCommandService.execute("removeItem", { - Path: "./test.txt" + Path: "./test.txt", }); setTimeout(() => { statefulProcessCommandProxy.shutdown();