Skip to content

Commit

Permalink
encoding/jsonschema: add test case for empty field
Browse files Browse the repository at this point in the history
I noticed that empty fields were inadvertently missed from some property
checks due to a flaw in the `patternProperties` logic. Add a test case
for this case, to be fixed in a subsequent CL.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I32e8341edb3ee73cdcbfa406ff4d51b2ce634c66
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1203596
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
rogpeppe committed Nov 5, 2024
1 parent 47c1559 commit 8850ea7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions encoding/jsonschema/testdata/txtar/pattern_with_empty_field.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This tests the case where there's a patternProperties keyword
# and no other fields.
# TODO the empty-field test should fail but currently does not.

-- schema.json --
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"patternProperties": {
".*": {
"type": "string"
}
}
}
-- out/decode/extract --
@jsonschema(schema="https://json-schema.org/draft/2020-12/schema")

{[=~".*" & !~"^()$"]: string}
...
-- test/empty-field.json --
{"": true}

0 comments on commit 8850ea7

Please sign in to comment.