mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Fail fast when input Buffer is empty #37
This commit is contained in:
parent
7319533969
commit
46b701c85c
6
index.js
6
index.js
@ -24,7 +24,11 @@ var Sharp = function(input) {
|
|||||||
if (typeof input === 'string') {
|
if (typeof input === 'string') {
|
||||||
this.options.fileIn = input;
|
this.options.fileIn = input;
|
||||||
} else if (typeof input ==='object' && input instanceof Buffer) {
|
} else if (typeof input ==='object' && input instanceof Buffer) {
|
||||||
this.options.bufferIn = input;
|
if (input.length > 0) {
|
||||||
|
this.options.bufferIn = input;
|
||||||
|
} else {
|
||||||
|
throw 'Buffer is empty';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw 'Unsupported input ' + typeof input;
|
throw 'Unsupported input ' + typeof input;
|
||||||
}
|
}
|
||||||
|
@ -209,12 +209,12 @@ async.series([
|
|||||||
},
|
},
|
||||||
// Rotate to an invalid angle, should fail
|
// Rotate to an invalid angle, should fail
|
||||||
function(done) {
|
function(done) {
|
||||||
var isValid = false;
|
var fail = false;
|
||||||
try {
|
try {
|
||||||
sharp(inputJpg).rotate(1);
|
sharp(inputJpg).rotate(1);
|
||||||
isValid = true;
|
fail = true;
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
assert(!isValid);
|
assert(!fail);
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
// Do not enlarge the output if the input width is already less than the output width
|
// Do not enlarge the output if the input width is already less than the output width
|
||||||
@ -252,6 +252,15 @@ async.series([
|
|||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
// Empty Buffer, should fail
|
||||||
|
function(done) {
|
||||||
|
var fail = false;
|
||||||
|
try {
|
||||||
|
sharp(new Buffer(0));
|
||||||
|
fail = true;
|
||||||
|
} catch (e) {}
|
||||||
|
assert(!fail);
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user