mirror of
https://github.com/go-ini/ini.git
synced 2026-06-19 21:46:45 +02:00
key: fix panic when recursive value has missing target (#191)
This commit is contained in:
@@ -147,10 +147,15 @@ func (k *Key) transformValue(val string) string {
|
||||
noption := vr[2 : len(vr)-2]
|
||||
|
||||
// Search in the same section.
|
||||
// If not found or found the key itself, then search again in default section.
|
||||
nk, err := k.s.GetKey(noption)
|
||||
if err != nil || k == nk {
|
||||
// Search again in default section.
|
||||
nk, _ = k.s.f.Section("").GetKey(noption)
|
||||
if nk == nil {
|
||||
// Stop when no results found in the default section,
|
||||
// and returns the value as-is.
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Substitute by new value and take off leading '%(' and trailing ')s'.
|
||||
|
||||
+12
@@ -551,7 +551,19 @@ NAME = %(NAME)s
|
||||
expires = %(expires)s`))
|
||||
So(err, ShouldBeNil)
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
So(f.Section("package").Key("NAME").String(), ShouldEqual, "ini")
|
||||
So(f.Section("package").Key("expires").String(), ShouldEqual, "yes")
|
||||
})
|
||||
|
||||
Convey("Recursive value with no target found", t, func() {
|
||||
f, err := ini.Load([]byte(`
|
||||
[foo]
|
||||
bar = %(missing)s
|
||||
`))
|
||||
So(err, ShouldBeNil)
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
So(f.Section("foo").Key("bar").String(), ShouldEqual, "%(missing)s")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user