Skip to content

Commit 17caa72

Browse files
committed
pkg/encoding/json: fix validator
cuelang.org/cl/1208701 introduced a bug where the call to Validate would refer to the original schema value, instead of the unified result. This could lead to spurious errors. Fixes #3932 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I03420535698b803c4f39a1a250c87243fdbb62be Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1215528 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 5d863b6 commit 17caa72

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

pkg/encoding/json/manual.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ func validate(c *adt.OpContext, b []byte, v pkg.Schema) (bool, error) {
148148
}
149149

150150
vx := adt.Unify(c, value.Vertex(v2), value.Vertex(v))
151-
x := value.Make(c, vx)
152-
if err := x.Err(); err != nil {
151+
v = value.Make(c, vx)
152+
if err := v.Err(); err != nil {
153153
return false, err
154154
}
155155

pkg/encoding/json/testdata/gen.txtar

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,7 @@ validate: {
152152
}
153153
}
154154
issue3932: {
155-
f: json.Validate({
156-
name!: string
157-
}) & json.Marshal({
158-
name: "foo"
159-
})
155+
f: "{\"name\":\"foo\"}"
160156
}
161157
valid: {
162158
t1: {

0 commit comments

Comments
 (0)