mirror of
https://github.com/go-ini/ini.git
synced 2026-06-19 21:46:45 +02:00
fix reflect from struct with multiple shadow keys (#254)
Co-authored-by: jmluang <350216438@qq.com> Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
This commit is contained in:
co-authored by
jmluang
ᴜɴᴋɴᴡᴏɴ
parent
f1d9ab1fbe
commit
8e98c6523e
@@ -479,7 +479,7 @@ func reflectSliceWithProperType(key *Key, field reflect.Value, delim string, all
|
||||
_ = keyWithShadows.AddShadow(val)
|
||||
}
|
||||
}
|
||||
key = keyWithShadows
|
||||
*key = *keyWithShadows
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -685,6 +685,29 @@ path = /tmp/gpm-profiles/test5.profile
|
||||
path = /tmp/gpm-profiles/test1.profile
|
||||
|
||||
`)
|
||||
|
||||
Convey("Reflect from struct with shadows", func() {
|
||||
cfg := ini.Empty(ini.LoadOptions{
|
||||
AllowShadows: true,
|
||||
})
|
||||
type ShadowStruct struct {
|
||||
StringArray []string `ini:"sa,,allowshadow"`
|
||||
EmptyStringArrat []string `ini:"empty,omitempty,allowshadow"`
|
||||
Allowshadow []string `ini:"allowshadow,,allowshadow"`
|
||||
}
|
||||
|
||||
So(ini.ReflectFrom(cfg, &ShadowStruct{StringArray: []string{"s1", "s2"}, Allowshadow: []string{"s3", "s4"}}), ShouldBeNil)
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err := cfg.WriteTo(&buf)
|
||||
So(err, ShouldBeNil)
|
||||
So(buf.String(), ShouldEqual, `sa = s1
|
||||
sa = s2
|
||||
allowshadow = s3
|
||||
allowshadow = s4
|
||||
|
||||
`)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user