Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

fix(go): match only JSON white space around a null Object

Adeshina Lasisidaa4fa4beff4
diff --git a/laya-go/lang/object_test.go b/laya-go/lang/object_test.go
index 94d80a22..a119e2aa 100644
--- a/laya-go/lang/object_test.go
+++ b/laya-go/lang/object_test.go
@@ -80,7 +80,7 @@ func TestObjectUnmarshalJSONNullAndTrailingData(t *testing.T) {
t.Errorf("null field: err %v, state %v", err, holder.State)
}
var direct Object
- for _, doc := range []string{`{} x`, `{"a":[1}`, `{"a":"b"} {}`} {
+ for _, doc := range []string{`{} x`, `{"a":[1}`, `{"a":"b"} {}`, "\u00a0null"} {
if err := direct.UnmarshalJSON([]byte(doc)); err == nil {
t.Errorf("%s must be refused", doc)
}
diff --git a/laya-go/lang/state.go b/laya-go/lang/state.go
index a1c435c4..1a7c4946 100644
--- a/laya-go/lang/state.go
+++ b/laya-go/lang/state.go
@@ -42,9 +42,9 @@ type Object []Member
// UnmarshalJSON decodes a JSON object keeping its key order, as Python's json.loads does: a
// repeated key keeps its first position and takes its last value. Nested objects become Objects
// and arrays become []any; numbers become float64, which a state ignores anyway. JSON null leaves
-// the Object unchanged, as encoding/json does for its own types.
+// the Object unchanged, the encoding/json convention for an Unmarshaler.
func (o *Object) UnmarshalJSON(data []byte) error {
- if string(bytes.TrimSpace(data)) == "null" {
+ if string(bytes.Trim(data, " \t\r\n")) == "null" { // JSON white space only
return nil
}
dec := json.NewDecoder(bytes.NewReader(data))