Skip to content

Commit 1692b8a

Browse files
Fix escaping property values. (microsoft#311)
Properly escape property value to handle non string types
1 parent 23f688b commit 1692b8a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vsts-task-lib",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "VSTS Task SDK",
55
"main": "./task.js",
66
"typings": "./task.d.ts",

node/taskcommand.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export class TaskCommand {
3232
if (this.properties.hasOwnProperty(key)) {
3333
var val = this.properties[key];
3434
if (val) {
35-
cmdStr += key + '=' + escape(val) + ';';
35+
// safely append the val - avoid blowing up when attempting to
36+
// call .replace() if message is not a string for some reason
37+
cmdStr += key + '=' + escape('' + (val || '')) + ';';
3638
}
3739
}
3840
}

node/test/commandtests.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ describe('Command Tests', function () {
5555
done();
5656
})
5757

58+
it('toString handles non string value in properties', function (done) {
59+
this.timeout(1000);
60+
61+
var tc = new tcm.TaskCommand('some.cmd', { foo: ['bar', 'baz'] }, 'cr \r lf \n crlf \r\n eom ] ;');
62+
assert(tc, 'TaskCommand constructor works');
63+
var cmdStr = tc.toString();
64+
assert.equal(cmdStr, '##vso[some.cmd foo=bar,baz;]cr %0D lf %0A crlf %0D%0A eom ] ;');
65+
done();
66+
})
67+
5868
it ('toString escapes properties', function (done) {
5969
this.timeout(1000);
6070

0 commit comments

Comments
 (0)