Skip to content

Commit 8ff3093

Browse files
authored
Ensure null is not treated as an object during validation (#4630)
1 parent 203f6e6 commit 8ff3093

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎lib/is.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const defined = (val) => typeof val !== 'undefined' && val !== null;
1313
* Is this value an object?
1414
* @private
1515
*/
16-
const object = (val) => typeof val === 'object';
16+
const object = (val) => typeof val === 'object' && val !== null;
1717

1818
/**
1919
* Is this value a plain object?

‎test/unit/composite.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,13 @@ suite('composite', () => {
371371
}, /Expected object for image to composite but received invalid of type string/);
372372
});
373373

374+
test('null image', (t) => {
375+
t.plan(1);
376+
t.assert.throws(() => {
377+
sharp().composite([null]);
378+
}, /Expected object for image to composite but received null of type object/);
379+
});
380+
374381
test('missing input', (t) => {
375382
t.plan(1);
376383
t.assert.throws(() => {

‎test/unit/extend.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ suite('Extend', () => {
155155
/Expected integer between 1 and 100000000 for extend but received -1 of type number/
156156
);
157157
});
158+
test('null fails', (t) => {
159+
t.plan(1);
160+
t.assert.throws(
161+
() => sharp().extend(null),
162+
/Expected integer or object for extend but received null of type object/
163+
);
164+
});
158165
test('too large fails', (t) => {
159166
t.plan(1);
160167
t.assert.throws(

0 commit comments

Comments
 (0)