From cc5d1d33f3d81b8d784f3ac29c70454ea36ae915 Mon Sep 17 00:00:00 2001 From: Garner Fox McCloud Date: Fri, 21 Dec 2018 10:51:09 -0500 Subject: [PATCH] Fix recursive char stripping when parsing recursive values --- key.go | 3 +-- key_test.go | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/key.go b/key.go index 7c8566a..26edb1c 100644 --- a/key.go +++ b/key.go @@ -133,8 +133,7 @@ func (k *Key) transformValue(val string) string { } // Take off leading '%(' and trailing ')s'. - noption := strings.TrimLeft(vr, "%(") - noption = strings.TrimRight(noption, ")s") + noption := vr[2 : len(vr)-2] // Search in the same section. nk, err := k.s.GetKey(noption) diff --git a/key_test.go b/key_test.go index a13ad95..c048dae 100644 --- a/key_test.go +++ b/key_test.go @@ -514,10 +514,13 @@ func TestRecursiveValues(t *testing.T) { Convey("Recursive values should not reflect on same key", t, func() { f, err := ini.Load([]byte(` NAME = ini +expires = yes [package] -NAME = %(NAME)s`)) +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") }) }