diff --git a/lib/shared/permissions.js b/lib/shared/permissions.js index e20e9c28..a9cce645 100644 --- a/lib/shared/permissions.js +++ b/lib/shared/permissions.js @@ -118,6 +118,21 @@ exports.getEnvironmentCommandPrefix = (environment) => { return _.concat([ 'env' ], argv); }; +/** + * @summary Quote a string + * @function + * @private + * + * @param {String} string - input string + * @returns {String} quoted string + * + * @example + * const result = quote('foo'); + */ +const quoteString = (string) => { + return `"${string}"`; +}; + /** * @summary Elevate a command * @function @@ -143,14 +158,22 @@ exports.getEnvironmentCommandPrefix = (environment) => { * }); */ exports.elevateCommand = (command, options) => { - const prefixedCommand = _.concat(exports.getEnvironmentCommandPrefix(options.environment), command); + const isWindows = os.platform() === 'win32'; - if (os.platform() === 'win32') { + const prefixedCommand = _.concat( + exports.getEnvironmentCommandPrefix(options.environment), + _.map(command, (string) => { + return isWindows ? quoteString(string) : string; + }) + ); + + if (isWindows) { const elevator = Bluebird.promisifyAll(nativeModule.load('elevator')); - return elevator.elevateAsync(_.concat([ + return elevator.elevateAsync([ 'cmd.exe', - '/c' - ], prefixedCommand)).then((results) => { + '/c', + quoteString(_.join(prefixedCommand, ' ')) + ]).then((results) => { return { cancelled: results.cancelled };