Skip to content

Commit

Permalink
Revert "escape spaces in sudo commands (fix #123)"
Browse files Browse the repository at this point in the history
This reverts commit 9988b3e.
  • Loading branch information
pstadler committed Mar 5, 2016
1 parent 4a6f83f commit f33d165
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 28 deletions.
5 changes: 2 additions & 3 deletions lib/transport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,3 @@ exports.escapeSingleQuotes = function(str) {

return str.replace(/'/g, "'\\''");
};

exports.escapeSpaces = function(str) {
if(!str) {
return str;
}

return str.replace(/ /g, '\\ ');
};
4 changes: 0 additions & 4 deletions test/test.transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
13 changes: 0 additions & 13 deletions test/test.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});

Expand Down

0 comments on commit f33d165

Please sign in to comment.