Skip to content
This repository has been archived by the owner on Mar 18, 2018. It is now read-only.

Commit

Permalink
Command containing quotes are now escaped.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Oct 8, 2014
1 parent bf128e0 commit 24460b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ssh/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ Connection.prototype.run = function (command, options, cb) {
var args = /^sudo/.exec(command) ? ['-tt'] : [];
args.push(remote.format(this.remote));

// Escape double quotes in command.
command = command.replace(/"/g, '\\"');

// Complete arguments.
args = ['ssh'].concat(args).concat(['"' + command + '"']);

Expand Down
9 changes: 9 additions & 0 deletions test/unit/ssh/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ describe('SSH Connection', function () {
);
});

it('should escape double quotes', function (done) {
connection.run('echo "ok"', {cwd: '/root'}, done);

expect(childProcess.exec).to.be.calledWith(
'ssh user@host "echo \\"ok\\""',
{ cwd: '/root', maxBuffer: 1000 * 1024 }
);
});

it('should handle childProcess.exec callback correctly', function (done) {
connection.run('my-command -x', { cwd: '/root' }, function(err, stdout, stderr) {
if (err) return done(err);
Expand Down

0 comments on commit 24460b4

Please sign in to comment.