diff --git a/lib/transport/index.js b/lib/transport/index.js index a8756a0..e9d99e7 100644 --- a/lib/transport/index.js +++ b/lib/transport/index.js @@ -7,7 +7,7 @@ var format = require('util').format , errors = require('../errors') , commands = require('./commands') , queue = require('../utils/queue') - , utils = require('../utils'); + , escapeSingleQuotes = require('../utils').escapeSingleQuotes; /** * A transport is the interface you use during flights. Basically they @@ -190,8 +190,7 @@ Transport.prototype.sudo = function(command, options) { var user = options.user || 'root'; command = format('%s%s', this._execWith, command); - command = utils.escapeSingleQuotes(command); - command = utils.escapeSpaces(command); + command = escapeSingleQuotes(command); command = format("sudo -u %s -i bash -c '%s'", user, command); return this._exec(command, options); diff --git a/lib/utils/index.js b/lib/utils/index.js index 75d74b9..0a8e6ca 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -24,11 +24,3 @@ exports.escapeSingleQuotes = function(str) { return str.replace(/'/g, "'\\''"); }; - -exports.escapeSpaces = function(str) { - if(!str) { - return str; - } - - return str.replace(/ /g, '\\ '); -}; diff --git a/test/test.transport.js b/test/test.transport.js index 0f9722a..0ada5ff 100644 --- a/test/test.transport.js +++ b/test/test.transport.js @@ -112,10 +112,6 @@ describe('transport', function() { transport.sudo("'cmd'"); expect(transport._exec.lastCall.args[0]).to.equal("sudo -u root -i bash -c ''\\''cmd'\\'''"); - - transport.sudo(' a b c '); - - expect(transport._exec.lastCall.args[0]).to.contain('\\ a\\ \\ b\\ c\\ '); }); it('should pass options to #_exec()', function() { diff --git a/test/test.utils.js b/test/test.utils.js index c61709f..93b179d 100644 --- a/test/test.utils.js +++ b/test/test.utils.js @@ -45,19 +45,6 @@ describe('utils', function() { expect(escapeSingleQuotes('"string"')).to.equal('"string"'); expect(escapeSingleQuotes("\\'string\\'")).to.equal("\\'\\''string\\'\\''"); expect(escapeSingleQuotes('')).to.equal(''); - expect(escapeSingleQuotes()).to.be.undefined; - }); - }); - - describe('#escapeSpaces()', function() { - it('should correctly escape single quotes', function() { - var escapeSpaces = proxyquire('../lib/utils', {}).escapeSpaces; - - expect(escapeSpaces('str str')).to.equal('str\\ str'); - expect(escapeSpaces(' str ')).to.equal('\\ str\\ \\ '); - expect(escapeSpaces('str str')).to.equal('str\\ \\ str'); - expect(escapeSpaces('')).to.equal(''); - expect(escapeSpaces()).to.be.undefined; }); });