From 17caa72c1406d82b4401fcb8bf404de7df4f78b4 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Tue, 20 May 2025 13:41:47 +0200 Subject: [PATCH] pkg/encoding/json: fix validator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: I03420535698b803c4f39a1a250c87243fdbb62be Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1215528 Unity-Result: CUE porcuepine Reviewed-by: Daniel Martí TryBot-Result: CUEcueckoo --- pkg/encoding/json/manual.go | 4 ++-- pkg/encoding/json/testdata/gen.txtar | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pkg/encoding/json/manual.go b/pkg/encoding/json/manual.go index 54368c1f5..688a83dcb 100644 --- a/pkg/encoding/json/manual.go +++ b/pkg/encoding/json/manual.go @@ -148,8 +148,8 @@ func validate(c *adt.OpContext, b []byte, v pkg.Schema) (bool, error) { } vx := adt.Unify(c, value.Vertex(v2), value.Vertex(v)) - x := value.Make(c, vx) - if err := x.Err(); err != nil { + v = value.Make(c, vx) + if err := v.Err(); err != nil { return false, err } diff --git a/pkg/encoding/json/testdata/gen.txtar b/pkg/encoding/json/testdata/gen.txtar index 2bcd7173c..e29056b7c 100644 --- a/pkg/encoding/json/testdata/gen.txtar +++ b/pkg/encoding/json/testdata/gen.txtar @@ -152,11 +152,7 @@ validate: { } } issue3932: { - f: json.Validate({ - name!: string - }) & json.Marshal({ - name: "foo" - }) + f: "{\"name\":\"foo\"}" } valid: { t1: { -- 2.51.2