Add shared internal UI toolkit for both readers

This commit is contained in:
ak47 committed 2026-11-12 01:27:42 -05:00
1 parent 672caca854
commit e49ba198d7
34 files changed
+3471

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package interaction
import (
"bytes"
"encoding/json"
"errors"
"strings"
)
// UnmarshalJSON keeps a malformed secret flag from silently becoming an
// ordinary entry (encoding/json otherwise accepts null for a boolean). The
// wire decoder separately rejects duplicate keys and bounds nesting/framing.
func (element *Element) UnmarshalJSON(data []byte) error {
type plain Element
var value plain
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
if err := decoder.Decode(&value); err != nil {
return err
}
var fields map[string]json.RawMessage
if err := json.Unmarshal(data, &fields); err != nil {
return err
}
for name, raw := range fields {
if strings.EqualFold(name, "secret") {
flag := string(bytes.TrimSpace(raw))
if name != "secret" || flag != "true" && flag != "false" {
return errors.New("secret must be a boolean")
}
}
}
*element = Element(value)
return nil
}