Skip to content

Commit

Permalink
{file, parser}: enforce default section name to lowercase with insent…
Browse files Browse the repository at this point in the history
…ive load (go-ini#125)
  • Loading branch information
unknwon committed Oct 26, 2017
1 parent 7ddae1f commit f280b3b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
12 changes: 12 additions & 0 deletions file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f280b3b

Please sign in to comment.