Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$data references pointing to an undefined object cause an exception #58

Open
jessepinho opened this issue Jun 19, 2015 · 0 comments
Open

Comments

@jessepinho
Copy link

Similar to #57, but for $data references: When a JSON schema has a $data reference to a key on an object that's undefined, JJV throws TypeError: Cannot call method 'hasOwnProperty' of undefined.

It appears that JJV calls hasOwnProperty() on the undefined value (inside resolveObjectRef) before checking that the value is in fact an object, resulting in this error.

How to handle this is unfortunately not explicitly defined in the v5 $data proposal, but I just wanted to point out that this is unexpected behavior.

To reproduce, run coffee test.coffee:

# test.coffee
jjv = require "jjv"

validator = jjv()

validator.addSchema "testSchema",
  type: "object"
  properties:
    a:
      type: "integer"
      minimum:
        "$data": "/b/c"

validator.validate "testSchema", a: 1, b: undefined

Note that the exception is not thrown when b is missing (in the above example)—only when it is explicitly set to undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant