Skip to content

Commit

Permalink
fix: disallow arrays as the object type (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
kudashevs authored Oct 30, 2024
1 parent ecbe944 commit 4b8acf2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ValidationError.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ function canApplyNot(schema) {
* @returns {boolean}
*/
function isObject(maybeObj) {
return typeof maybeObj === "object" && maybeObj !== null;
return (
typeof maybeObj === "object" &&
!Array.isArray(maybeObj) &&
maybeObj !== null
);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,13 @@ exports[`Validation should fail validation for object in object with anyOf 1`] =
[object { alias?, name?, onlyModule? }, ...]"
`;
exports[`Validation should fail validation for object type 1`] = `
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.devServer should be an object:
object {}
-> Options for the webpack-dev-server"
`;
exports[`Validation should fail validation for object with dependencies #2 1`] = `
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.objectWithPropertyDependency2 should be an object:
Expand Down
8 changes: 8 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,14 @@ describe("Validation", () => {
(msg) => expect(msg).toMatchSnapshot()
);

createFailedTestCase(
"object type",
{
devServer: [],
},
(msg) => expect(msg).toMatchSnapshot()
);

createFailedTestCase(
"array type",
{
Expand Down

0 comments on commit 4b8acf2

Please sign in to comment.