Skip to content

Commit

Permalink
Fix escaping property values. (#311)
Browse files Browse the repository at this point in the history
Properly escape property value to handle non string types
  • Loading branch information
stephenmichaelf committed Feb 8, 2018
1 parent 91e03a1 commit b7b47e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vsts-task-lib",
"version": "2.2.0",
"version": "2.2.1",
"description": "VSTS Task SDK",
"main": "./task.js",
"typings": "./task.d.ts",
Expand Down
4 changes: 3 additions & 1 deletion node/taskcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export class TaskCommand {
if (this.properties.hasOwnProperty(key)) {
var val = this.properties[key];
if (val) {
cmdStr += key + '=' + escape(val) + ';';
// safely append the val - avoid blowing up when attempting to
// call .replace() if message is not a string for some reason
cmdStr += key + '=' + escape('' + (val || '')) + ';';
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions node/test/commandtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ describe('Command Tests', function () {
done();
})

it('toString handles non string value in properties', function (done) {
this.timeout(1000);

var tc = new tcm.TaskCommand('some.cmd', { foo: ['bar', 'baz'] }, 'cr \r lf \n crlf \r\n eom ] ;');
assert(tc, 'TaskCommand constructor works');
var cmdStr = tc.toString();
assert.equal(cmdStr, '##vso[some.cmd foo=bar,baz;]cr %0D lf %0A crlf %0D%0A eom ] ;');
done();
})

it ('toString escapes properties', function (done) {
this.timeout(1000);

Expand Down

0 comments on commit b7b47e4

Please sign in to comment.