Skip to content

Add metaschema tests for patternProperties #576

Closed as not planned
Closed as not planned
@hansdals

Description

@hansdals

Hi. I'm working on a schema validator for C using json-c. It's called jsonc-daccord.

Currently I'm running my test runner on the Test Suite tests/draft2020-12/patternProperties.json,

I noticed that it does not cover invalid regex patterns, and it does not cover "ignore non-object schemas"

The draft https://json-schema.org/draft/2020-12/json-schema-core.html#name-patternproperties says

  • The value of "patternProperties" MUST be an object.
    What if it isn't ? Shall the patternProperties keyword be ignored ?
  • Each property name of this object SHOULD be a valid regular expression, according to the ECMA-262 regular expression dialect
    When it says SHOULD, it means it is recommended.. Here is my problem, I need to test my code for handling of a failed regex since C code can risk of running into segfaults and memory leaks, but since the draft indicates it is recommended, how should the outcome of the test be? If we put a test in the patternProperties.json file, the result cannot be both true and false (or ignore). I wonder if somehow the tests "valid" field should have allowed for "ignore" as well as "true" and "false". A "valid": "ignore" would increase the coverage of the tests. Or perhaps better, to make it backwards compatible, a new field could be added to the json next to "valid", it could says "ignore": true.

for clarity, here is what I suggest:

[
        {
            "description":
                "patternProperties with invalid regex",
            "schema": {
                "patternProperties": {
                    "invalid regex, I cannot thing of one right now :)": {"type": "integer"}
                }
            },
            "tests": [
                {
                    "description": "a single valid match is valid",
                    "data": {"foo": 1},
                    "valid": true,
                    "ignore-result": true
                },
            ]
        }
]

What do you think ? :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAn enhancement to the tooling or structure of the suite (as opposed to a new test).good first issueAn issue that is a good candidate for new contributorsmissing testA request to add a test to the suite that is currently not covered elsewhere.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions