mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 08:30:54 +00:00
Fixed #1735 Return empty []string
Need return empty []string if config value is empty. split `“”` ==> []string{}, Not []string{“”}
This commit is contained in:
parent
70e63570f5
commit
8ff74e71cb
@ -270,7 +270,11 @@ func (c *IniConfigContainer) DefaultString(key string, defaultval string) string
|
||||
|
||||
// Strings returns the []string value for a given key.
|
||||
func (c *IniConfigContainer) Strings(key string) []string {
|
||||
return strings.Split(c.String(key), ";")
|
||||
v := c.String(key)
|
||||
if v == "" {
|
||||
return []string{}
|
||||
}
|
||||
return strings.Split(v, ";")
|
||||
}
|
||||
|
||||
// DefaultStrings returns the []string value for a given key.
|
||||
|
@ -71,6 +71,7 @@ peers = one;two;three
|
||||
"null": "",
|
||||
"demo2::key1": "",
|
||||
"error": "",
|
||||
"emptystrings": []string{},
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -174,7 +174,11 @@ func (c *ConfigContainer) DefaultString(key string, defaultval string) string {
|
||||
|
||||
// Strings returns the []string value for a given key.
|
||||
func (c *ConfigContainer) Strings(key string) []string {
|
||||
return strings.Split(c.String(key), ";")
|
||||
v := c.String(key)
|
||||
if v == "" {
|
||||
return []string{}
|
||||
}
|
||||
return strings.Split(v, ";")
|
||||
}
|
||||
|
||||
// DefaultStrings returns the []string value for a given key.
|
||||
|
@ -82,4 +82,7 @@ func TestXML(t *testing.T) {
|
||||
if xmlconf.String("name") != "astaxie" {
|
||||
t.Fatal("get name error")
|
||||
}
|
||||
if len(xmlconf.Strings("emptystrings")) != 0 {
|
||||
t.Fatal("get emtpy strings error")
|
||||
}
|
||||
}
|
||||
|
@ -211,7 +211,11 @@ func (c *ConfigContainer) DefaultString(key string, defaultval string) string {
|
||||
|
||||
// Strings returns the []string value for a given key.
|
||||
func (c *ConfigContainer) Strings(key string) []string {
|
||||
return strings.Split(c.String(key), ";")
|
||||
v := c.String(key)
|
||||
if v == "" {
|
||||
return []string{}
|
||||
}
|
||||
return strings.Split(v, ";")
|
||||
}
|
||||
|
||||
// DefaultStrings returns the []string value for a given key.
|
||||
|
@ -79,4 +79,8 @@ func TestYaml(t *testing.T) {
|
||||
if yamlconf.String("name") != "astaxie" {
|
||||
t.Fatal("get name error")
|
||||
}
|
||||
|
||||
if len(yamlconf.Strings("emptystrings")) != 0 {
|
||||
t.Fatal("get emtpy strings error")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user