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..54a4e76 100644 --- a/parser.go +++ b/parser.go @@ -222,7 +222,6 @@ func hasSurroundedQuote(in string, quote byte) bool { } func (p *parser) readValue(in []byte, bufferSize int) (string, error) { - line := strings.TrimLeftFunc(string(in), unicode.IsSpace) if len(line) == 0 { if p.options.AllowPythonMultilineValues && len(in) > 0 && in[len(in)-1] == '\n' { @@ -304,12 +303,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 } @@ -481,7 +475,6 @@ func (f *File) parse(reader io.Reader) (err error) { key.Comment = strings.TrimSpace(p.comment.String()) p.comment.Reset() continue - case f.options.SkipUnrecognizableLines: continue } 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