Skip to content

Commit

Permalink
fix bug with escaped quotes in toolrunner _argStringToArray (microsof…
Browse files Browse the repository at this point in the history
…t#771)

* fix escaped quotes in toolrunner

* add unit test for escaped quotes

* fix output

* fix console

* format code

Co-authored-by: Anna Opareva <v-aopareva@microsoft.com>
  • Loading branch information
AnnaOpareva and Anna Opareva authored Jun 29, 2021
1 parent 777d53d commit 672c911
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 9 additions & 1 deletion node/test/toolrunnertests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,15 @@ describe('Toolrunner Tests', function () {
assert.equal((node as any).args.toString(), '--path,/bin/working folder1', 'should be --path /bin/working folder1');
done();
})

it('handles escaped quotes', function (done) {
this.timeout(10000);
var node = tl.tool(tl.which('node', true));
node.line('-TEST="escaped\\\"quotes" -x');
node.arg('-y');
assert.equal((node as any).args.length, 3, 'should have 3 args');
assert.equal((node as any).args.toString(), '-TEST=escaped"quotes,-x,-y', 'should be -TEST=escaped"quotes,-x,-y');
done();
})
if (process.platform != 'win32') {
it('exec prints [command] (OSX/Linux)', function (done) {
this.timeout(10000);
Expand Down
9 changes: 6 additions & 3 deletions node/toolrunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ export class ToolRunner extends events.EventEmitter {

var append = function (c: string) {
// we only escape double quotes.
if (escaped && c !== '"') {
arg += '\\';
if (escaped) {
if (c !== '"') {
arg += '\\';
} else {
arg.slice(0, -1);
}
}

arg += c;
escaped = false;
}
Expand Down

0 comments on commit 672c911

Please sign in to comment.