jsonschema icon indicating copy to clipboard operation
jsonschema copied to clipboard

`Symbol` does not trigger error with `additionalProperties: false`

Open gabssnake opened this issue 4 years ago • 0 comments

Hi there, thank you for your good work !

It seems additionalProperties which have a Symbol key do not throw with throwError.

What am I doing wrong? Is this expected behavior?

const assert = require("assert").strict;
const validate = require("jsonschema").validate;

const schema = {
  type: "object",
  properties: {
    msg: { type: "string" }
  },
  additionalProperties: false
};

// Missing expected exception
assert.throws(() => {
  validate({ msg: "hello", [Symbol("stealth")]: "oops" }, schema, { throwError: true });
});

assert.doesNotThrow(() => {
  validate({ msg: "hello" }, schema, { throwError: true });
});

assert.throws(() => {
  validate({ msg: "hello", extra: "boom" }, schema, { throwError: true });
});

gabssnake avatar Jul 08 '21 18:07 gabssnake