Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python multiline EOF error #309

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions ini_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 1 addition & 6 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions testdata/multiline_eof.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
value1 = some text here
some more text here 2