mirror of
https://github.com/lovell/sharp.git
synced 2025-07-14 04:40:13 +02:00
Tighten validation of page/pages constructor options
This commit is contained in:
parent
075771d1e9
commit
5a9b6c8afd
@ -65,11 +65,15 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
if (is.defined(inputOptions.pages)) {
|
if (is.defined(inputOptions.pages)) {
|
||||||
if (is.integer(inputOptions.pages) && is.inRange(inputOptions.pages, -1, 100000)) {
|
if (is.integer(inputOptions.pages) && is.inRange(inputOptions.pages, -1, 100000)) {
|
||||||
inputDescriptor.pages = inputOptions.pages;
|
inputDescriptor.pages = inputOptions.pages;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('pages', 'integer between -1 and 100000', inputOptions.pages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(inputOptions.page)) {
|
if (is.defined(inputOptions.page)) {
|
||||||
if (is.integer(inputOptions.page) && is.inRange(inputOptions.page, 0, 100000)) {
|
if (is.integer(inputOptions.page) && is.inRange(inputOptions.page, 0, 100000)) {
|
||||||
inputDescriptor.page = inputOptions.page;
|
inputDescriptor.page = inputOptions.page;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('page', 'integer between 0 and 100000', inputOptions.page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Create new image
|
// Create new image
|
||||||
|
@ -648,6 +648,16 @@ describe('Input/output', function () {
|
|||||||
it('Ignore unknown attribute', function () {
|
it('Ignore unknown attribute', function () {
|
||||||
sharp(null, { unknown: true });
|
sharp(null, { unknown: true });
|
||||||
});
|
});
|
||||||
|
it('Invalid page property throws', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp(null, { page: -1 });
|
||||||
|
}, /Expected integer between 0 and 100000 for page but received -1 of type number/);
|
||||||
|
});
|
||||||
|
it('Invalid pages property throws', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp(null, { pages: '1' });
|
||||||
|
}, /Expected integer between -1 and 100000 for pages but received 1 of type string/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('create new image', function () {
|
describe('create new image', function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user