Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly escape property value to handle non string types #311

Merged
merged 3 commits into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 message - avoid blowing up when attempting to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message => val

// call .replace() if message is not a string for some reason
cmdStr += key + '=' + escape('' + (val || '')) + ';';
}
}
}
Expand Down
26 changes: 26 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 array 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 Expand Up @@ -97,6 +107,22 @@ describe('Command Tests', function () {
done();
})

it('parses cmd with array value in properties', function (done) {
var cmdStr = '##vso[basic.command prop1=bar,baz;]messageVal';

var tc = tcm.commandFromString(cmdStr);

assert(tc.command === 'basic.command', 'cmd should be correct');
assert(tc.properties['prop1'], 'should be a property names prop1');
assert.equal(Object.keys(tc.properties).length, 1, 'should have one property.');

console.log('UNKWNOWN VALUE: ' + JSON.stringify(tc.properties['prop1']));

assert.equal(tc.properties['prop1'], ['bar', 'baz'], 'property value is correct');
assert.equal(tc.message, 'messageVal', 'message is correct');
done();
})

it('parses basic cmd with multiple properties no trailing semi', function (done) {
var cmdStr = '##vso[basic.command prop1=val1;prop2=val2]messageVal';

Expand Down