mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Detect empty input and throw a helpful error (#2687)
This commit is contained in:
@@ -335,17 +335,6 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail when input is empty Buffer', function (done) {
|
||||
sharp(Buffer.alloc(0)).toBuffer().then(function () {
|
||||
assert(false);
|
||||
done();
|
||||
}).catch(function (err) {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Input buffer contains unsupported image format', err.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail when input is invalid Buffer', function (done) {
|
||||
sharp(Buffer.from([0x1, 0x2, 0x3, 0x4])).toBuffer().then(function () {
|
||||
assert(false);
|
||||
|
||||
@@ -7,6 +7,18 @@ const fixtures = require('../fixtures');
|
||||
|
||||
describe('Raw pixel data', function () {
|
||||
describe('Raw pixel input', function () {
|
||||
it('Empty data', function () {
|
||||
assert.throws(function () {
|
||||
sharp(Buffer.from(''));
|
||||
}, /empty/);
|
||||
assert.throws(function () {
|
||||
sharp(new Uint8Array(0));
|
||||
}, /empty/);
|
||||
assert.throws(function () {
|
||||
sharp(new Uint8ClampedArray(0));
|
||||
}, /empty/);
|
||||
});
|
||||
|
||||
it('Missing options', function () {
|
||||
assert.throws(function () {
|
||||
sharp({ raw: {} });
|
||||
|
||||
Reference in New Issue
Block a user