Skip to content

Commit

Permalink
encoding/jsonschema: non-string regular expressions should error
Browse files Browse the repository at this point in the history
The error from `Value.String` was being ignored. Use `strValue` instead,
which gives an error if the value is not a string.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: If599225bd9f3e2f5db6db3153dd0a40c01393504
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201124
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
rogpeppe committed Sep 12, 2024
1 parent a227239 commit f811ee7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion encoding/jsonschema/constraints_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func constraintMinLength(key string, n cue.Value, s *state) {
}

func constraintPattern(key string, n cue.Value, s *state) {
str, _ := n.String()
str, _ := s.strValue(n)
if _, err := regexp.Compile(str); err != nil {
if s.cfg.StrictFeatures {
// TODO check if the error is only because of an unsupported
Expand Down
11 changes: 11 additions & 0 deletions encoding/jsonschema/testdata/txtar/invalid_pattern.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Invalid patterns should result in failure

-- schema.json --
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"pattern": 1234
}
-- out/decode/extract --
ERROR:
invalid string:
schema.json:3:5

0 comments on commit f811ee7

Please sign in to comment.