diff --git a/config/ini.go b/config/ini.go index da6f2b3a..a690ede0 100644 --- a/config/ini.go +++ b/config/ini.go @@ -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. diff --git a/config/ini_test.go b/config/ini_test.go index 11063d99..93fce61f 100644 --- a/config/ini_test.go +++ b/config/ini_test.go @@ -71,6 +71,7 @@ peers = one;two;three "null": "", "demo2::key1": "", "error": "", + "emptystrings": []string{}, } ) diff --git a/config/xml/xml.go b/config/xml/xml.go index ffb32862..2757b0bc 100644 --- a/config/xml/xml.go +++ b/config/xml/xml.go @@ -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. diff --git a/config/xml/xml_test.go b/config/xml/xml_test.go index fa3c17f1..308e257d 100644 --- a/config/xml/xml_test.go +++ b/config/xml/xml_test.go @@ -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") + } } diff --git a/config/yaml/yaml.go b/config/yaml/yaml.go index 9a96ac92..9a4fb2e9 100644 --- a/config/yaml/yaml.go +++ b/config/yaml/yaml.go @@ -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. diff --git a/config/yaml/yaml_test.go b/config/yaml/yaml_test.go index 19ecdca1..3bbaaa32 100644 --- a/config/yaml/yaml_test.go +++ b/config/yaml/yaml_test.go @@ -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") + } }