mirror of
https://github.com/go-ini/ini.git
synced 2026-06-19 21:46:45 +02:00
{file, parser}: enforce default section name to lowercase with insentive load (#125)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user