Fix decoding of integer keys of map type (#829)

* fix decoding integer keys of map type

* use createDecodedNewValue for map key
This commit is contained in:
Masaaki Goshima 2025-12-02 12:31:53 +09:00 committed by GitHub
parent a7b4bfbcf4
commit 9e98b0c753
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View file

@ -1750,14 +1750,11 @@ func (d *Decoder) decodeMap(ctx context.Context, dst reflect.Value, src ast.Node
return err
}
} else {
keyVal, err := d.nodeToValue(ctx, key)
keyVal, err := d.createDecodedNewValue(ctx, keyType, reflect.Value{}, key)
if err != nil {
return err
}
k = reflect.ValueOf(keyVal)
if k.IsValid() && k.Type().ConvertibleTo(keyType) {
k = k.Convert(keyType)
}
k = keyVal
}
if k.IsValid() {

View file

@ -1280,6 +1280,14 @@ c:
source: `"\uD83D\uDE00a\uD83D\uDE01"`,
value: "😀a😁",
},
{
source: "42: 100",
value: map[string]any{"42": 100},
},
{
source: "42: 100",
value: map[int]any{42: 100},
},
}
for _, test := range tests {
t.Run(test.source, func(t *testing.T) {