~nilium/go-ini

78ffead5915239d3139cc7fe357cb13926d9558c — Noel Cower 7 years ago f4ad7ee
Handle case where EOF is the first error seen

Previously, a completely empty stream (i.e., EOF on first read) would
result in an unexpected EOF. This should've been a non-error, since
reading nothing just means nothing's been decoded -- i.e., no values,
nothing wrong.

Change-Id: Id762e57eaa2d73c21633cca5081cf0c089730731
2 files changed, 7 insertions(+), 0 deletions(-)

M ini.go
M ini_test.go
M ini.go => ini.go +3 -0
@@ 536,6 536,9 @@ func (d *decoder) readSubsection() (next nextfunc, err error) {

func (d *decoder) start() (next nextfunc, err error) {
	_, _, err = d.nextRune()
	if err == io.EOF {
		return nil, nil
	}
	return d.readElem, err
}


M ini_test.go => ini_test.go +4 -0
@@ 54,6 54,10 @@ func TestReadINI_section_badspace(t *testing.T) {
}

func TestReadINIEmpty(t *testing.T) {
	testReadINIMatching(t, nil, "", Values{})
}

func TestReadININoValues(t *testing.T) {
	testReadINIMatching(t, nil, "\n\t\n;empty\n\t\n\t", Values{})
}