Skip to content

Commit

Permalink
escaping filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Apr 29, 2011
1 parent f60627d commit d287d2b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions index.js
@@ -1,6 +1,12 @@

// gm - Copyright Aaron Heckmann <aaron.heckmann+github@gmail.com> (MIT Licensed)

/**
* Module dependencies.
*/

var escape = require('./lib/utils').escape;

/**
* Constructor.
*
Expand Down Expand Up @@ -32,6 +38,8 @@ function gm (source, height, color) {
}

this.arg(arg);
} else {
source = escape(source);
}

this.source = source;
Expand Down
10 changes: 8 additions & 2 deletions lib/command.js
@@ -1,9 +1,12 @@

// gm - Copyright Aaron Heckmann <aaron.heckmann+github@gmail.com> (MIT Licensed)

// -- commandline
/**
* Module dependencies.
*/

var exec = require('child_process').exec;
var escape = require('./utils').escape;

module.exports = function (proto) {

Expand All @@ -30,7 +33,10 @@ module.exports = function (proto) {
throw new TypeError("gm().write() expects a filename when writing new files")
}

this.outname = name;
if (name) {
this.outname = escape(name);
}

return this._exec(this.cmd(), callback);
}

Expand Down
14 changes: 14 additions & 0 deletions lib/utils.js
@@ -0,0 +1,14 @@

// gm - Copyright Aaron Heckmann <aaron.heckmann+github@gmail.com> (MIT Licensed)

/**
* Escape the given shell `arg`.
*
* @param {String} arg
* @return {String}
* @api public
*/

exports.escape = function escape (arg) {
return '"' + String(arg).trim().replace(/"/g, '\\"') + '"';
}

0 comments on commit d287d2b

Please sign in to comment.