Upstream gookit/config state of the touched files before db5b338b76
This commit is contained in:
1 parent
cb6b9f9456
commit
a78ca9b221
2 files changed
+6
-27
No files matched your search
@@ -63,19 +63,19 @@ func (c *Config) Exists(key string, findByPath ...bool) (ok bool) {
|
|||||||
}
|
}
|
||||||
case []int: // is array(is from Set)
|
case []int: // is array(is from Set)
|
||||||
i, err := strconv.Atoi(k)
|
i, err := strconv.Atoi(k)
|
||||||
if err != nil || i < 0 || i >= len(typeData) {
|
if err != nil || i >= len(typeData) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
item = typeData[i]
|
item = typeData[i]
|
||||||
case []string: // is array(is from Set)
|
case []string: // is array(is from Set)
|
||||||
i, err := strconv.Atoi(k)
|
i, err := strconv.Atoi(k)
|
||||||
if err != nil || i < 0 || i >= len(typeData) {
|
if err != nil || i >= len(typeData) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
item = typeData[i]
|
item = typeData[i]
|
||||||
case []any: // is array(load from file)
|
case []any: // is array(load from file)
|
||||||
i, err := strconv.Atoi(k)
|
i, err := strconv.Atoi(k)
|
||||||
if err != nil || i < 0 || i >= len(typeData) {
|
if err != nil || i >= len(typeData) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
item = typeData[i]
|
item = typeData[i]
|
||||||
@@ -214,7 +214,7 @@ func (c *Config) GetValue(key string, findByPath ...bool) (value any, ok bool) {
|
|||||||
i, err := strconv.Atoi(k)
|
i, err := strconv.Atoi(k)
|
||||||
|
|
||||||
// check slice index
|
// check slice index
|
||||||
if err != nil || i < 0 || len(typeData) <= i {
|
if err != nil || len(typeData) <= i {
|
||||||
ok = false
|
ok = false
|
||||||
c.addError(err)
|
c.addError(err)
|
||||||
return
|
return
|
||||||
@@ -223,7 +223,7 @@ func (c *Config) GetValue(key string, findByPath ...bool) (value any, ok bool) {
|
|||||||
item = typeData[i]
|
item = typeData[i]
|
||||||
case []string: // is array(is from Set)
|
case []string: // is array(is from Set)
|
||||||
i, err := strconv.Atoi(k)
|
i, err := strconv.Atoi(k)
|
||||||
if err != nil || i < 0 || len(typeData) <= i {
|
if err != nil || len(typeData) <= i {
|
||||||
ok = false
|
ok = false
|
||||||
c.addError(err)
|
c.addError(err)
|
||||||
return
|
return
|
||||||
@@ -232,7 +232,7 @@ func (c *Config) GetValue(key string, findByPath ...bool) (value any, ok bool) {
|
|||||||
item = typeData[i]
|
item = typeData[i]
|
||||||
case []any: // is array(load from file)
|
case []any: // is array(load from file)
|
||||||
i, err := strconv.Atoi(k)
|
i, err := strconv.Atoi(k)
|
||||||
if err != nil || i < 0 || len(typeData) <= i {
|
if err != nil || len(typeData) <= i {
|
||||||
ok = false
|
ok = false
|
||||||
c.addError(err)
|
c.addError(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -499,24 +499,3 @@ func TestConfig_Duration_getter(t *testing.T) {
|
|||||||
is.Eq(7*time.Second, c.Duration("missing", 7*time.Second))
|
is.Eq(7*time.Second, c.Duration("missing", 7*time.Second))
|
||||||
is.Eq(time.Duration(0), c.Duration("missing"))
|
is.Eq(time.Duration(0), c.Duration("missing"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfig_GetValue_negativeIndex(t *testing.T) {
|
|
||||||
is := assert.New(t)
|
|
||||||
|
|
||||||
c := New("test-neg")
|
|
||||||
err := c.LoadData(map[string]any{
|
|
||||||
"arr": []any{"a", "b", "c"},
|
|
||||||
})
|
|
||||||
is.NoErr(err)
|
|
||||||
|
|
||||||
// A negative slice index must not panic; it is simply not found.
|
|
||||||
is.NotPanics(func() {
|
|
||||||
v, ok := c.GetValue("arr.-1")
|
|
||||||
is.False(ok)
|
|
||||||
is.Nil(v)
|
|
||||||
})
|
|
||||||
|
|
||||||
is.NotPanics(func() {
|
|
||||||
is.False(c.Exists("arr.-1"))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user