Skip to content

Commit

Permalink
[knf] Fixed bug with using method 'Is' for checking for empty values
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Mar 12, 2023
1 parent 4eab0c2 commit b264d3b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### 12.62.1

* `[knf]` Fixed bug with using method `Is` for checking for empty values

### 12.62.0

* `[system/containers]` More precise method for checking container engine
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "12.62.0"
const VERSION = "12.62.1"

// ////////////////////////////////////////////////////////////////////////////////// //

Expand Down
12 changes: 4 additions & 8 deletions knf/knf.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func Is(name string, value any) bool {
return global.Is(name, value)
}

// HasSection checks if section exist
// HasSection checks if the section exists
func HasSection(section string) bool {
if global == nil {
return false
Expand All @@ -216,7 +216,7 @@ func HasSection(section string) bool {
return global.HasSection(section)
}

// HasProp checks if property exist
// HasProp checks if the property is defined and set
func HasProp(name string) bool {
if global == nil {
return false
Expand Down Expand Up @@ -506,10 +506,6 @@ func (c *Config) Is(name string, value any) bool {
return false
}

if !c.HasProp(name) {
return false
}

switch t := value.(type) {
case string:
return c.GetS(name) == t
Expand All @@ -534,7 +530,7 @@ func (c *Config) Is(name string, value any) bool {
return false
}

// HasSection checks if section exist
// HasSection checks if section exists
func (c *Config) HasSection(section string) bool {
if c == nil || c.mx == nil {
return false
Expand All @@ -546,7 +542,7 @@ func (c *Config) HasSection(section string) bool {
return c.data[strings.ToLower(section)] == "!"
}

// HasProp checks if property exist
// HasProp checks if property is defined and set
func (c *Config) HasProp(name string) bool {
if c == nil || c.mx == nil {
return false
Expand Down
3 changes: 2 additions & 1 deletion knf/knf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (s *KNFSuite) TestErrors(c *check.C) {
c.Assert(config.GetB("test"), check.Equals, false)
c.Assert(config.GetM("test"), check.Equals, os.FileMode(0))
c.Assert(config.GetD("test"), check.Equals, time.Duration(0))
c.Assert(config.Is("test", ""), check.Equals, false)
c.Assert(config.Is("test", ""), check.Equals, true)
c.Assert(config.HasSection("test"), check.Equals, false)
c.Assert(config.HasProp("test"), check.Equals, false)
c.Assert(config.Sections(), check.HasLen, 0)
Expand Down Expand Up @@ -382,6 +382,7 @@ func (s *KNFSuite) TestIs(c *check.C) {
c.Assert(err, check.IsNil)

c.Assert(Is("string:test1", "test"), check.Equals, true)
c.Assert(Is("string:test6", ""), check.Equals, true)
c.Assert(Is("boolean:test1", true), check.Equals, true)
c.Assert(Is("integer:test1", 1), check.Equals, true)
c.Assert(Is("integer:test6", 123.4), check.Equals, true)
Expand Down

0 comments on commit b264d3b

Please sign in to comment.