summaryrefslogtreecommitdiffstats
path: root/lib/utils/command.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-05-02 15:09:09 +0200
committerSamy Pessé <samypesse@gmail.com>2016-05-02 15:09:10 +0200
commitde47db2b666fd03b18a8478136c4414c37523063 (patch)
tree292e8e1cf92a829fe6366645d3884a48e93fe29b /lib/utils/command.js
parentfa6fcffbe122ec9b4723d5906f9daad348c6172b (diff)
downloadgitbook-de47db2b666fd03b18a8478136c4414c37523063.zip
gitbook-de47db2b666fd03b18a8478136c4414c37523063.tar.gz
gitbook-de47db2b666fd03b18a8478136c4414c37523063.tar.bz2
Fix escaping of ebook-convert options
Diffstat (limited to 'lib/utils/command.js')
-rw-r--r--lib/utils/command.js33
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/utils/command.js b/lib/utils/command.js
index 083e72e..7311856 100644
--- a/lib/utils/command.js
+++ b/lib/utils/command.js
@@ -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) {
+
+ if (is.bool(value)) {
result.push(key);
+ } else {
+ result.push(key + '=' + escapeShellArg(value));
}
-
- result.push(key + '=' + escapeShellArg(value));
}
return result.join(' ');