fix(encode): propagate invalid UTF-8 key errors from headers and inline tables
Assisted-by: GLM 5.3
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user