Prevent panic when decoding string named types (#743)

This commit is contained in:
Shuhei Kitagawa 2025-05-26 02:14:35 +02:00 committed by GitHub
parent 04f9bb53f7
commit 6a6c998c2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 7 deletions

View file

@ -25,6 +25,8 @@ type Child struct {
C int `yaml:"-"`
}
type TestString string
func TestDecoder(t *testing.T) {
tests := []struct {
source string
@ -35,6 +37,10 @@ func TestDecoder(t *testing.T) {
source: "v: hi\n",
value: map[string]string{"v": "hi"},
},
{
source: "v: hi\n",
value: map[string]TestString{"v": "hi"},
},
{
source: "v: \"true\"\n",
value: map[string]string{"v": "true"},
@ -55,6 +61,10 @@ func TestDecoder(t *testing.T) {
source: "v: 10\n",
value: map[string]string{"v": "10"},
},
{
source: "v: 10\n",
value: map[string]TestString{"v": "10"},
},
{
source: "v: -10\n",
value: map[string]string{"v": "-10"},