Skip to content

Commit

Permalink
Merge pull request #866 from orbitjs/fix-validate-object
Browse files Browse the repository at this point in the history
validateObject should not accept null as a valid object
  • Loading branch information
dgeb committed Jul 16, 2021
2 parents 14519a7 + ca01cee commit 22674a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@orbit/validators/src/object-validator.ts
Expand Up @@ -22,7 +22,7 @@ export const validateObject: ObjectValidator = (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
options?: ObjectValidationOptions
): undefined | ObjectValidationIssue[] => {
if (typeof input !== 'object') {
if (typeof input !== 'object' || input === null) {
return [
{
validator: 'object',
Expand Down
8 changes: 8 additions & 0 deletions packages/@orbit/validators/test/object-validator-test.ts
Expand Up @@ -7,6 +7,14 @@ const { module, test } = QUnit;
module('validateObject', function (hooks) {
test('validates type', function (assert) {
assert.strictEqual(validateObject({}), undefined);
assert.deepEqual(validateObject(null as any), [
{
validator: 'object',
validation: 'type',
ref: null as any,
description: 'is not an object'
}
]);
assert.deepEqual(validateObject('not-an-object' as any), [
{
validator: 'object',
Expand Down

0 comments on commit 22674a0

Please sign in to comment.