Opened 10 years ago

Closed 10 years ago

#8898 closed defect (fixed)

JSON Schema Validation Error

Reported by: Jarrod Carlson Owned by: Kris Zyp
Priority: high Milestone: 1.3
Component: Dojox Version: 1.3.0b3
Keywords: json schema validate Cc:
Blocked By: Blocking:

Description

After defining a schema for my domain model, the dojox.json.schema.validate() methods did not identify an error in an intentionally invalid instance.

Here is a portion of my schema, with the description type intentionally set to "integer". The actual type returned is a string, but this is intended to demonstrate the failure.

    var schema = {
        "event": {
            "description": "Details for an Event object",
            "type": "object",
            "properties": {
                /** FIELDS **/
                "description": {
                    "type": "integer",
                    "optional": true
                },
                "name": {
                    "type": "string"
                }
            }
        }
    }
    

Here is an instance of this schema:

    var event = {
      "name": "March 1st Event",
      "description": "Something is happeneing today."
    }

Finally, we validate the instance against the schema:

    dojo.require("dojox.json.schema");
    var r = dojox.json.schema.validate(event, schema);
    dojox.json.schema.mustBeValid(r);

The fault occurs around line 79 of dojox.json.schema.js:

78    if (typeof type == 'string' && type != 'any' &&
79        (type == 'null' ? value !== null : typeof value != type) &&
80        !(value instanceof Array && type == 'array') &&
81        !(type == 'integer' && !(value%1))) {
82            return [{property:path,message:(typeof value) + " value found, but a " + type + " is required"}];
83    }

In this if statement, type = 'integer', value = 'Something is happeneing today.'. The fault occurs when, on line 79, the type is not null, and thus typeof value != type => false. Because of that, the entire statement is false, and execution does not enter the block to create an error description.

I am unsure if this bug was introduced in 1.3.0b3 or 1.3.0rc1. I am using (and discovered the bug in) 1.3.0rc1.

Change History (3)

comment:1 Changed 10 years ago by Adam Peller

Owner: changed from Adam Peller to Kris Zyp

comment:2 Changed 10 years ago by Kris Zyp

Can I go ahead and commit a fix for this or am I too late for 1.3?

comment:3 Changed 10 years ago by bill

Resolution: fixed
Status: newclosed

Fixed in [17038].

Note: See TracTickets for help on using tickets.