mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +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).
|
* Ensure `sharp.format.vips` is present and correct (filesystem only).
|
||||||
[#1813](https://github.com/lovell/sharp/issues/1813)
|
[#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`.
|
* Allow use of 'heic' and 'heif' identifiers with `toFormat`.
|
||||||
[#1834](https://github.com/lovell/sharp/pull/1834)
|
[#1834](https://github.com/lovell/sharp/pull/1834)
|
||||||
[@jaubourg](https://github.com/jaubourg)
|
[@jaubourg](https://github.com/jaubourg)
|
||||||
|
@ -210,12 +210,20 @@ function resize (width, height, options) {
|
|||||||
}
|
}
|
||||||
if (is.object(options)) {
|
if (is.object(options)) {
|
||||||
// Width
|
// Width
|
||||||
if (is.integer(options.width) && options.width > 0) {
|
if (is.defined(options.width)) {
|
||||||
this.options.width = 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
|
// Height
|
||||||
if (is.integer(options.height) && options.height > 0) {
|
if (is.defined(options.height)) {
|
||||||
this.options.height = 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
|
// Fit
|
||||||
if (is.defined(options.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/);
|
}, /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) {
|
it('Invalid width - too large', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(0x4000, 1)
|
.resize(0x4000, 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user