From 0526ee6812ed4dccef27811af05812ff43ca793e Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 2 Feb 2016 23:08:44 +0100 Subject: [PATCH] Fixed bug in HasProp method which return true for unset properties --- changelog.md | 4 ++++ knf/knf.go | 24 +++++++++++------------- knf/knf_test.go | 4 ++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/changelog.md b/changelog.md index 7ae6f535..c15ccbcc 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ ## Changelog +#### v1.5.1 + +* `[knf]` Fixed bug in HasProp method which return true for unset properties + #### v1.5.0 * `[tmp]` Improved error handling diff --git a/knf/knf.go b/knf/knf.go index 180dabc7..496eb036 100644 --- a/knf/knf.go +++ b/knf/knf.go @@ -275,9 +275,9 @@ func (c *Config) GetS(name string, defvals ...string) string { return "" } - val, ok := c.data[name] + val := c.data[name] - if !ok || val == "" { + if val == "" { if len(defvals) == 0 { return "" } @@ -294,9 +294,9 @@ func (c *Config) GetI(name string, defvals ...int) int { return 0 } - val, ok := c.data[name] + val := c.data[name] - if !ok || val == "" { + if val == "" { if len(defvals) == 0 { return 0 } @@ -330,9 +330,9 @@ func (c *Config) GetF(name string, defvals ...float64) float64 { return 0.0 } - val, ok := c.data[name] + val := c.data[name] - if !ok || val == "" { + if val == "" { if len(defvals) == 0 { return 0.0 } @@ -355,9 +355,9 @@ func (c *Config) GetB(name string, defvals ...bool) bool { return false } - val, ok := c.data[name] + val := c.data[name] - if !ok || val == "" { + if val == "" { if len(defvals) == 0 { return false } @@ -379,9 +379,9 @@ func (c *Config) GetM(name string, defvals ...os.FileMode) os.FileMode { return 0 } - val, ok := c.data[name] + val := c.data[name] - if !ok || val == "" { + if val == "" { if len(defvals) == 0 { return 0 } @@ -413,9 +413,7 @@ func (c *Config) HasProp(name string) bool { return false } - _, ok := c.data[name] - - return ok + return c.data[name] != "" } // Sections return slice with section names diff --git a/knf/knf_test.go b/knf/knf_test.go index aa5bb91c..e514b6fd 100644 --- a/knf/knf_test.go +++ b/knf/knf_test.go @@ -252,8 +252,8 @@ func (s *KNFSuite) TestCheckers(c *check.C) { c.Assert(HasSection("strings"), check.Equals, false) c.Assert(HasProp("string:test1"), check.Equals, true) - c.Assert(HasProp("string:test9"), check.Equals, false) - c.Assert(HasProp("strings:test9"), check.Equals, false) + c.Assert(HasProp("string:test6"), check.Equals, false) + c.Assert(HasProp("strings:test6"), check.Equals, false) } func (s *KNFSuite) TestFormating(c *check.C) {