Skip to content

Commit ad374a0

Browse files
authored
Fixed argument value bleed into the next empty argument (#19)
* Fixed bleeding value of the command argument into the next empty valued argument
1 parent c8f363e commit ad374a0

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

psCommandService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ PSCommandService.prototype._generateCommand = function(commandConfig, argument2V
304304

305305
var passedArgValue = passedArgValues[i];
306306

307-
var valueToSet;
307+
var valueToSet = "";
308308

309309
if (passedArgValue && passedArgValue != 'undefined') {
310310
valueToSet = passedArgValue;

test/unit.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,29 @@ const commandRegistry = {
8484
type: "text",
8585
},
8686
},
87+
setContent: {
88+
command: "Set-Content {{{arguments}}}",
89+
arguments: {
90+
'Path': {},
91+
'Value': {},
92+
'Filter': {},
93+
},
94+
},
95+
getContent: {
96+
command: "Get-Content {{{arguments}}}",
97+
arguments: {
98+
'Path': {},
99+
},
100+
return: {
101+
type: "text",
102+
},
103+
},
104+
removeItem: {
105+
command: "Remove-Item {{{arguments}}}",
106+
arguments: {
107+
'Path': {},
108+
},
109+
},
87110
};
88111

89112

@@ -580,4 +603,53 @@ describe("test PSCommandService w/ o365CommandRegistry", function () {
580603
throw e;
581604
}
582605
});
606+
it("Should test value bleeding", async function () {
607+
this.timeout(10000);
608+
const statefulProcessCommandProxy = new StatefulProcessCommandProxy({
609+
name: "Powershell pool",
610+
max: 1,
611+
min: 1,
612+
idleTimeoutMS: 30000,
613+
614+
logFunction: logFunction,
615+
processCommand: "pwsh",
616+
processArgs: ["-Command", "-"],
617+
processRetainMaxCmdHistory: 30,
618+
processCwd: null,
619+
processEnvMap: null,
620+
processUid: null,
621+
processGid: null,
622+
initCommands: initCommands,
623+
validateFunction: (processProxy) => processProxy.isValid(),
624+
});
625+
626+
const psCommandService = new PSCommandService(
627+
statefulProcessCommandProxy,
628+
commandRegistry,
629+
myLogFunction
630+
);
631+
try {
632+
const newResult = await psCommandService.execute("setContent", {
633+
Path: "./test.txt",
634+
Value: "Test",
635+
Filter: ""
636+
});
637+
assert.equal(newResult.command.trim(), "Set-Content -Path './test.txt' -Value 'Test'");
638+
assert.equal(newResult.stderr, "");
639+
const getResult = await psCommandService.execute("getContent", {
640+
Path: "./test.txt",
641+
});
642+
assert.equal(getResult.stderr, "");
643+
assert.equal(getResult.stdout, "Test");
644+
} catch (e) {
645+
assert.fail(e);
646+
} finally {
647+
await psCommandService.execute("removeItem", {
648+
Path: "./test.txt",
649+
});
650+
setTimeout(() => {
651+
statefulProcessCommandProxy.shutdown();
652+
}, 5000);
653+
}
654+
});
583655
});

0 commit comments

Comments
 (0)