Skip to content

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

Description

@jessepinho

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions