{file, parser}: enforce default section name to lowercase with insentive load (#125)

This commit is contained in:
Unknwon
2017-10-26 14:46:43 -04:00
parent 7ddae1ffd1
commit f280b3ba51
4 changed files with 20 additions and 3 deletions
+2 -1
View File
@@ -109,7 +109,8 @@ func (f *File) NewSections(names ...string) (err error) {
func (f *File) GetSection(name string) (*Section, error) {
if len(name) == 0 {
name = DEFAULT_SECTION
} else if f.options.Insensitive {
}
if f.options.Insensitive {
name = strings.ToLower(name)
}
+12
View File
@@ -150,6 +150,18 @@ func TestFile_Section(t *testing.T) {
So(sec.Name(), ShouldEqual, "404")
})
})
Convey("Get default section in lower case with insensitive load", t, func() {
f, err := ini.InsensitiveLoad([]byte(`
[default]
NAME = ini
VERSION = v1`))
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
So(f.Section("").Key("name").String(), ShouldEqual, "ini")
So(f.Section("").Key("version").String(), ShouldEqual, "v1")
})
}
func TestFile_Sections(t *testing.T) {
+1 -1
View File
@@ -32,7 +32,7 @@ const (
// Maximum allowed depth when recursively substituing variable names.
_DEPTH_VALUES = 99
_VERSION = "1.30.2"
_VERSION = "1.30.3"
)
// Version returns current package version literal.
+5 -1
View File
@@ -255,7 +255,11 @@ func (f *File) parse(reader io.Reader) (err error) {
}
// Ignore error because default section name is never empty string.
section, _ := f.NewSection(DEFAULT_SECTION)
name := DEFAULT_SECTION
if f.options.Insensitive {
name = strings.ToLower(DEFAULT_SECTION)
}
section, _ := f.NewSection(name)
var line []byte
var inUnparseableSection bool