Skip to content

Commit f58efab

Browse files
committed
Fix ImageMagick/GraphicsMagick path with a space.
1 parent d23d7a1 commit f58efab

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- fixed: a waiting mode in `GETSCHEMA()`
2121
- fixed: cache `instance.cache()` in RESTBuilder
2222
- fixed: NoSQL filtering (critical)
23+
- fixed: a bug ImageMagick/GraphicsMagick when the path contains spaces (critical)
2324

2425
======= 2.5.0
2526

image.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/**
2323
* @module FrameworkImage
24-
* @version 2.5.0
24+
* @version 2.6.0
2525
*/
2626

2727
'use strict';
@@ -34,6 +34,7 @@ const Fs = require('fs');
3434
const REGEXP_SVG = /(width=\"\d+\")+|(height=\"\d+\")+/g;
3535
const REGEXP_PATH = /\//g;
3636
const REGEXP_ESCAPE = /\'/g;
37+
const D = require('os').platform().substring(0, 3).toLowerCase() === 'win' ? '"' : '\'';
3738

3839
var CACHE = {};
3940
var middlewares = {};
@@ -404,7 +405,7 @@ Image.prototype.push = function(key, value, priority, encode) {
404405

405406
if (value != null) {
406407
if (encode && typeof(value) === 'string')
407-
cmd += ' \'' + value.replace(REGEXP_ESCAPE, '') + '\'';
408+
cmd += ' ' + D + value.replace(REGEXP_ESCAPE, '') + D;
408409
else
409410
cmd += ' ' + value;
410411
}
@@ -673,7 +674,7 @@ Image.prototype.sepia = function() {
673674
};
674675

675676
Image.prototype.watermark = function(filename, x, y, w, h) {
676-
return this.push('-draw', 'image over {1},{2} {3},{4} \'{0}\''.format(filename, x || 0, y || 0, w || 0, h || 0), 6, true);
677+
return this.push('-draw', 'image over {1},{2} {3},{4} {5}{0}{5}'.format(filename, x || 0, y || 0, w || 0, h || 0, D), 6, true);
677678
};
678679

679680
Image.prototype.make = function(fn) {
@@ -686,7 +687,7 @@ Image.prototype.command = function(key, value, priority, esc) {
686687
};
687688

688689
function wrap(command, empty) {
689-
return (empty ? ' ' : '') + '\'' + command.replace(REGEXP_ESCAPE, '') + '\'';
690+
return (empty ? ' ' : '') + D + command.replace(REGEXP_ESCAPE, '') + D;
690691
}
691692

692693
exports.Image = Image;

0 commit comments

Comments
 (0)