mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Prevent writing output file over input file - closes #28
This commit is contained in:
parent
6c96bd0d37
commit
e32faac17a
8
index.js
8
index.js
@ -107,9 +107,13 @@ Sharp.prototype.resize = function(width, height) {
|
||||
|
||||
Sharp.prototype.write = function(output, callback) {
|
||||
if (!output || output.length === 0) {
|
||||
throw 'Invalid output';
|
||||
callback('Invalid output');
|
||||
} else {
|
||||
this._sharp(output, callback);
|
||||
if (this.options.inFile === output) {
|
||||
callback('Cannot use same file for input and output');
|
||||
} else {
|
||||
this._sharp(output, callback);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
@ -145,5 +145,12 @@ async.series([
|
||||
done();
|
||||
});
|
||||
});
|
||||
},
|
||||
// Attempt to output to input, should fail
|
||||
function(done) {
|
||||
sharp(inputJpg).write(inputJpg, function(err) {
|
||||
assert(!!err);
|
||||
done();
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user