From 3ca1e6ad324e3b4b4cb107e6c5117f4ec475de08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Henrique=20Guard=C3=A3o=20Gandarez?= <782854+gandarez@users.noreply.github.com> Date: Thu, 2 Dec 2021 05:56:40 -0300 Subject: [PATCH] Fix python multiline EOF error (#309) --- ini_test.go | 23 +++++++++++++++++++++++ parser.go | 7 +------ testdata/multiline_eof.ini | 2 ++ 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 testdata/multiline_eof.ini diff --git a/ini_test.go b/ini_test.go index 8a21eae..ed57568 100644 --- a/ini_test.go +++ b/ini_test.go @@ -1562,3 +1562,26 @@ func TestPythonMultiline(t *testing.T) { testData.Value3, ) } + +func TestPythonMultiline_EOF(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Skipping testing on Windows") + } + + path := filepath.Join("testdata", "multiline_eof.ini") + f, err := LoadSources(LoadOptions{ + AllowPythonMultilineValues: true, + ReaderBufferSize: 64 * 1024, + }, path) + require.NoError(t, err) + require.NotNil(t, f) + assert.Len(t, f.Sections(), 1) + + defaultSection := f.Section("") + assert.NotNil(t, f.Section("")) + + var testData testData + err = defaultSection.MapTo(&testData) + require.NoError(t, err) + assert.Equal(t, "some text here\n\tsome more text here 2", testData.Value1) +} diff --git a/parser.go b/parser.go index ca76f5f..0eb08f1 100644 --- a/parser.go +++ b/parser.go @@ -304,12 +304,7 @@ func (p *parser) readPythonMultilines(line string, bufferSize int) (string, erro for { peekData, peekErr := peekBuffer.ReadBytes('\n') - if peekErr != nil { - if peekErr == io.EOF { - p.debug("readPythonMultilines: io.EOF, peekData: %q, line: %q", string(peekData), line) - return line, nil - } - + if peekErr != nil && peekErr != io.EOF { p.debug("readPythonMultilines: failed to peek with error: %v", peekErr) return "", peekErr } diff --git a/testdata/multiline_eof.ini b/testdata/multiline_eof.ini new file mode 100644 index 0000000..1ef99ba --- /dev/null +++ b/testdata/multiline_eof.ini @@ -0,0 +1,2 @@ +value1 = some text here + some more text here 2 \ No newline at end of file