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

encoding/jsonschema: patternProperties does not quote field names in regexp pattern #3551

Closed
rogpeppe opened this issue Nov 4, 2024 · 0 comments

Comments

@rogpeppe
Copy link
Member

rogpeppe commented Nov 4, 2024

What version of CUE are you using (cue version)?

deed7d5c

Does this issue reproduce with the latest stable release?

Yes (v0.10.0)

What did you do?

exec cue mod init
exec cue import -p main schema.json
! exec cue vet . data.json
-- data.json --
{
    "cue": 123
}
-- schema.json --
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "c.e": {
            "type": "boolean"
        }
    },
    "patternProperties": {
        ".*": {
            "type": "string"
        }
    }
}

What did you expect to see?

A passing test. The patternProperties keyword applies only to properties that aren't
explicitly defined. The jsonschema logic tries to work around the lack of support
for ... T in structs (c.f. the "Types for all elements versus remaining elements" section
in #165) by including the other field names in a regexp, but it does not quote metacharacters
in their names, so the field name cue, which should come under the auspices of
patternProperties in this example, doesn't get checked at all.

What did you see instead?

> exec cue mod init
> exec cue import -p main schema.json
> exec cat schema.cue
[stdout]
package main

@jsonschema(schema="http://json-schema.org/draft-07/schema#")
"c.e"?: bool

{[=~".*" & !~"^(c.e)$"]: string}
...
> ! exec cue vet . data.json
FAIL: /tmp/z.txtar:4: unexpected command success
cueckoo pushed a commit that referenced this issue Nov 5, 2024
Add a test case to be fixed in next CL.

For #3551.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: If7a8f14692ea2e34dc451c237e64eaf923c85dda
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1203608
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
@cueckoo cueckoo closed this as completed in 85f5ca8 Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant