From 8cd603a2b1ada7f72cf97e08c3ab87c80cdb664e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 2 Sep 2026 12:59:12 +0200 Subject: [PATCH] Key the repeated-item check on the string itself; marshal only objects --- node.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/node.go b/node.go index 7859521..793c4f7 100644 --- a/node.go +++ b/node.go @@ -153,11 +153,15 @@ func compileChoice(items []any) (node, error) { func checkNoRepeatedItem(items []any) error { seen := make(map[string]int, len(items)) for i, raw := range items { - key, err := json.Marshal(raw) - if err != nil { - return err + key, isString := raw.(string) + if !isString { + b, err := json.Marshal(raw) + if err != nil { + return err + } + key = "\x00" + string(b) } - if j, dup := seen[string(key)]; dup { + if j, dup := seen[key]; dup { if s, isString := raw.(string); isString { return fmt.Errorf("choice item %q is repeated; skew the odds with a weight instead: { \"format\": %q, \"weight\": 2 }", s, s) }