danielaparker / jsoncons

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
https://danielaparker.github.io/jsoncons
Other
726 stars 164 forks source link

Validation with a schema using "format" causes constraints on other elements to not apply in validation. #524

Closed MohammadHossein-Namjoo closed 5 months ago

MohammadHossein-Namjoo commented 5 months ago

When validating with a JSON Schema that uses "format" in one of its properties, other properties are validated (even with wrong values)

Example schema: exampleSchema.json

Example JSON to validate:

{ "ipv4": "192.168.1.123", "someNumber": 256 }

When validating the given JSON against the given schema Expectation: The validation should fail because 256 is bigger than the maximum specified in the schema.

Actual Behavior: The validation passes.

    ojson schema = ojson::parse(schemaStringStream.str());

    jsonschema::json_schema<ojson> compiledSchema =
        jsonschema::make_json_schema(schema,
                                     Resolver,
                                     jsonschema::evaluation_options()
                                         .require_format_validation(true));
    const std::string INVALID_DATA = R"(
{
    "ipv4": "192.168.1.123",
    "someNumber": 256
}
    )";
    compiledSchema.is_valid(ojson::parse(INVALID_DATA)));

NOTE If the schema is changed to use a "pattern" instead of the "format", this issue does not happen.

What compiler, architecture, and operating system?

What jsoncons library version? master - f393930fb58a884e317fa50a19faa441a3a998b5

danielaparker commented 5 months ago

I believe that's the same as #520, fixed in latest release 0.176.0. (https://github.com/danielaparker/jsoncons/commit/f393930fb58a884e317fa50a19faa441a3a998b5 predates the fix)

danielaparker commented 5 months ago

I'm closing this as it appears to be a duplicate of an issue already fixed.