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

Fix crash when 'additionalProperties' is a schema #105

Closed
wants to merge 1 commit into from

Conversation

twitchard
Copy link

To fix the following bug

[richard@tigger blah]$ cat blah.js 
var revalidator = require('revalidator')
var object = { 
    foo: 'bar'
}

var schema = { 
    properties: { 
        "baz": { 
            type: 'string',
            required: true
        }
    },
    additionalProperties: 
    {
        type: 'string',
        description: 'This will crash revalidator' 
    },
    type: 'object' }

return revalidator.validate(object, schema)
[richard@tigger blah]$ node blah.js

/home/richard/blah/node_modules/revalidator/lib/revalidator.js:278
    if (schema.format && options.validateFormats) {
              ^
TypeError: Cannot read property 'format' of undefined
    at validateProperty (/home/richard/blah/node_modules/revalidator/lib/revalidator.js:278:15)
    at validateObject (/home/richard/blah/node_modules/revalidator/lib/revalidator.js:232:11)
    at Object.validate (/home/richard/blah/node_modules/revalidator/lib/revalidator.js:35:7)
    at Object.<anonymous> (/home/richard/blah/blah.js:20:20)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

@Swaagie
Copy link
Member

Swaagie commented Sep 16, 2015

Hmm is the if logic around the the call for unvisitedProperties, seems contra-dictionary. In any case could you add a test please, that invalidates the old behaviour for instance

@twitchard twitchard closed this Sep 26, 2024
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

Successfully merging this pull request may close these issues.

2 participants