From 83c3027ef938217c4b602d9272d3e55718c0820e Mon Sep 17 00:00:00 2001 From: Stephen Franceschelli Date: Thu, 8 Feb 2018 11:54:37 -0500 Subject: [PATCH 1/3] Fix. --- node/package.json | 2 +- node/taskcommand.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/node/package.json b/node/package.json index a64b541f7..01beaec27 100644 --- a/node/package.json +++ b/node/package.json @@ -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", diff --git a/node/taskcommand.ts b/node/taskcommand.ts index b8aee389e..1d03d81bd 100644 --- a/node/taskcommand.ts +++ b/node/taskcommand.ts @@ -32,7 +32,7 @@ export class TaskCommand { if (this.properties.hasOwnProperty(key)) { var val = this.properties[key]; if (val) { - cmdStr += key + '=' + escape(val) + ';'; + cmdStr += key + '=' + escape('' + (val || '')) + ';'; } } } From 65876117f21187b3b7ee3043058033deea58ac62 Mon Sep 17 00:00:00 2001 From: Stephen Franceschelli Date: Thu, 8 Feb 2018 13:24:13 -0500 Subject: [PATCH 2/3] Add tests and comment. --- node/taskcommand.ts | 2 ++ node/test/commandtests.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/node/taskcommand.ts b/node/taskcommand.ts index 1d03d81bd..6a8854a05 100644 --- a/node/taskcommand.ts +++ b/node/taskcommand.ts @@ -32,6 +32,8 @@ export class TaskCommand { if (this.properties.hasOwnProperty(key)) { var val = this.properties[key]; if (val) { + // safely append the message - avoid blowing up when attempting to + // call .replace() if message is not a string for some reason cmdStr += key + '=' + escape('' + (val || '')) + ';'; } } diff --git a/node/test/commandtests.ts b/node/test/commandtests.ts index 2ca72f77c..1236187be 100644 --- a/node/test/commandtests.ts +++ b/node/test/commandtests.ts @@ -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); @@ -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'; From 554d88f4bc6d97c6d4b456c0f6dc40939b282e83 Mon Sep 17 00:00:00 2001 From: Stephen Franceschelli Date: Thu, 8 Feb 2018 13:31:38 -0500 Subject: [PATCH 3/3] Cleanup. --- node/taskcommand.ts | 2 +- node/test/commandtests.ts | 18 +----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/node/taskcommand.ts b/node/taskcommand.ts index 6a8854a05..1634bac0b 100644 --- a/node/taskcommand.ts +++ b/node/taskcommand.ts @@ -32,7 +32,7 @@ export class TaskCommand { if (this.properties.hasOwnProperty(key)) { var val = this.properties[key]; if (val) { - // safely append the message - avoid blowing up when attempting to + // 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 || '')) + ';'; } diff --git a/node/test/commandtests.ts b/node/test/commandtests.ts index 1236187be..4a7ea9012 100644 --- a/node/test/commandtests.ts +++ b/node/test/commandtests.ts @@ -55,7 +55,7 @@ describe('Command Tests', function () { done(); }) - it('toString handles array value in properties', 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 ] ;'); @@ -107,22 +107,6 @@ 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';