fix(encode): propagate invalid UTF-8 key errors from headers and inline tables

Assisted-by: GLM 5.3
This commit is contained in:
2026-09-17 23:06:59 +02:00
parent ec0d7a0023
commit 54c6032a9a
3 changed files with 46 additions and 17 deletions
+11
View File
@@ -1128,6 +1128,17 @@ func TestMarshalKeyRequiresUTF8(t *testing.T) {
if _, err := Marshal(m); err == nil {
t.Errorf("expected error for invalid UTF-8 key")
}
// The check must reach the keys of table headers and of inline tables
// nested inside value arrays, not only scalar keys: both write keys
// through the same path.
nested := map[string]any{"\xff": map[string]any{"k": "v"}}
if _, err := Marshal(nested); err == nil {
t.Errorf("expected error for invalid UTF-8 table header key")
}
inline := map[string]any{"mix": []any{1, map[string]any{"\xff": 1}}}
if _, err := Marshal(inline); err == nil {
t.Errorf("expected error for invalid UTF-8 inline table key")
}
}
func TestMarshalStringRequiresUTF8(t *testing.T) {