diff --git a/CHANGELOG.md b/CHANGELOG.md index 146e0552..9dd26d92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ - Fix 4736: set a fixed value "/" to the "Path" of "_xsrf" cookie. [4736](https://github.com/beego/beego/issues/4735) [4739](https://github.com/beego/beego/issues/4739) - Fix 4734: do not reset id in Delete function. [4738](https://github.com/beego/beego/pull/4738) [4742](https://github.com/beego/beego/pull/4742) - Fix 4699: Remove Remove goyaml2 dependency. [4755](https://github.com/beego/beego/pull/4755) +- Fix 4698: Prompt error when config format is incorrect. [4757](https://github.com/beego/beego/pull/4757) ## Fix Sonar diff --git a/core/config/xml/xml.go b/core/config/xml/xml.go index 067d4811..c260d3b5 100644 --- a/core/config/xml/xml.go +++ b/core/config/xml/xml.go @@ -70,7 +70,17 @@ func (xc *Config) ParseData(data []byte) (config.Configer, error) { return nil, err } - x.data = config.ExpandValueEnvForMap(d["config"].(map[string]interface{})) + v := d["config"] + if v == nil { + return nil, fmt.Errorf("xml parse should include in tags") + } + + confVal, ok := v.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("xml parse tags should include sub tags") + } + + x.data = config.ExpandValueEnvForMap(confVal) return x, nil } diff --git a/core/config/xml/xml_test.go b/core/config/xml/xml_test.go index c71488fe..2807be69 100644 --- a/core/config/xml/xml_test.go +++ b/core/config/xml/xml_test.go @@ -26,7 +26,7 @@ import ( func TestXML(t *testing.T) { var ( - // xml parse should incluce in tags + // xml parse should include in tags xmlcontext = ` beeapi @@ -150,6 +150,25 @@ func TestXML(t *testing.T) { assert.Equal(t, "MySection", sec.Name) } +func TestXMLMissConfig(t *testing.T) { + xmlcontext1 := ` + + beeapi + ` + + c := &Config{} + _, err := c.ParseData([]byte(xmlcontext1)) + assert.Equal(t, "xml parse should include in tags", err.Error()) + + xmlcontext2 := ` + + + ` + + _, err = c.ParseData([]byte(xmlcontext2)) + assert.Equal(t, "xml parse tags should include sub tags", err.Error()) +} + type Section struct { Name string `xml:"name"` }