mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 02:30:12 +02:00
Ensure invalid resize width/height as options throw #1817
This commit is contained in:
parent
da4e05c118
commit
69fe21a7ec
@ -9,6 +9,9 @@ Requires libvips v8.8.1.
|
||||
* Ensure `sharp.format.vips` is present and correct (filesystem only).
|
||||
[#1813](https://github.com/lovell/sharp/issues/1813)
|
||||
|
||||
* Ensure invalid `width` and `height` provided as options to `resize` throw.
|
||||
[#1817](https://github.com/lovell/sharp/issues/1817)
|
||||
|
||||
* Allow use of 'heic' and 'heif' identifiers with `toFormat`.
|
||||
[#1834](https://github.com/lovell/sharp/pull/1834)
|
||||
[@jaubourg](https://github.com/jaubourg)
|
||||
|
@ -210,12 +210,20 @@ function resize (width, height, options) {
|
||||
}
|
||||
if (is.object(options)) {
|
||||
// Width
|
||||
if (is.integer(options.width) && options.width > 0) {
|
||||
this.options.width = options.width;
|
||||
if (is.defined(options.width)) {
|
||||
if (is.integer(options.width) && options.width > 0) {
|
||||
this.options.width = options.width;
|
||||
} else {
|
||||
throw is.invalidParameterError('width', 'positive integer', options.width);
|
||||
}
|
||||
}
|
||||
// Height
|
||||
if (is.integer(options.height) && options.height > 0) {
|
||||
this.options.height = options.height;
|
||||
if (is.defined(options.height)) {
|
||||
if (is.integer(options.height) && options.height > 0) {
|
||||
this.options.height = options.height;
|
||||
} else {
|
||||
throw is.invalidParameterError('height', 'positive integer', options.height);
|
||||
}
|
||||
}
|
||||
// Fit
|
||||
if (is.defined(options.fit)) {
|
||||
|
@ -87,6 +87,18 @@ describe('Resize dimensions', function () {
|
||||
}, /Expected positive integer for height but received 1.5 of type number/);
|
||||
});
|
||||
|
||||
it('Invalid width - via options', () => {
|
||||
assert.throws(() => {
|
||||
sharp().resize({ width: 1.5, height: 240 });
|
||||
}, /Expected positive integer for width but received 1.5 of type number/);
|
||||
});
|
||||
|
||||
it('Invalid height - via options', () => {
|
||||
assert.throws(() => {
|
||||
sharp().resize({ width: 320, height: 1.5 });
|
||||
}, /Expected positive integer for height but received 1.5 of type number/);
|
||||
});
|
||||
|
||||
it('Invalid width - too large', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(0x4000, 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user