mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 11:26:31 +00:00
Fix escaping of ebook-convert options
This commit is contained in:
+27
-8
@@ -1,3 +1,4 @@
|
||||
var is = require('is');
|
||||
var childProcess = require('child_process');
|
||||
var spawn = require('spawn-cmd').spawn;
|
||||
var Promise = require('./promise');
|
||||
@@ -54,12 +55,29 @@ function spawnCmd(command, args, options) {
|
||||
return d.promise;
|
||||
}
|
||||
|
||||
// Transform an option object to a command line string
|
||||
function escapeShellArg(s) {
|
||||
s = s.replace(/"/g, '\\"');
|
||||
return '"' + s + '"';
|
||||
/**
|
||||
Transform an option object to a command line string
|
||||
|
||||
@param {String|number} value
|
||||
@param {String}
|
||||
*/
|
||||
function escapeShellArg(value) {
|
||||
if (is.number(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
value = String(value);
|
||||
value = value.replace(/"/g, '\\"');
|
||||
|
||||
return '"' + value + '"';
|
||||
}
|
||||
|
||||
/**
|
||||
Transform a map of options into a command line arguments string
|
||||
|
||||
@param {Object} options
|
||||
@return {String}
|
||||
*/
|
||||
function optionsToShellArgs(options) {
|
||||
var result = [];
|
||||
|
||||
@@ -69,11 +87,12 @@ function optionsToShellArgs(options) {
|
||||
if (value === null || value === undefined || value === false) {
|
||||
continue;
|
||||
}
|
||||
if (value === true) {
|
||||
result.push(key);
|
||||
}
|
||||
|
||||
result.push(key + '=' + escapeShellArg(value));
|
||||
if (is.bool(value)) {
|
||||
result.push(key);
|
||||
} else {
|
||||
result.push(key + '=' + escapeShellArg(value));
|
||||
}
|
||||
}
|
||||
|
||||
return result.join(' ');
|
||||
|
||||
Reference in New Issue
Block a user