From f79afbf793ce3d6ebf54fb336ead46e6bf6d5c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Henrique=20Guard=C3=A3o=20Gandarez?= Date: Mon, 6 Sep 2021 00:05:31 -0300 Subject: [PATCH] Fix parsing python multiline string --- ini_python_multiline_test.go | 4 ++-- parser.go | 17 +---------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/ini_python_multiline_test.go b/ini_python_multiline_test.go index 9070c29..c29fbfc 100644 --- a/ini_python_multiline_test.go +++ b/ini_python_multiline_test.go @@ -36,8 +36,8 @@ func TestMultiline(t *testing.T) { var testData testData err = defaultSection.MapTo(&testData) So(err, ShouldBeNil) - So(testData.Value1, ShouldEqual, "some text here\nsome more text here\n\nthere is an empty line above and below\n") - So(testData.Value2, ShouldEqual, "there is an empty line above\nthat is not indented so it should not be part\nof the value") + So(testData.Value1, ShouldEqual, "some text here\n\tsome more text here\n\t\n\tthere is an empty line above and below\n\t") + So(testData.Value2, ShouldEqual, "there is an empty line above\n that is not indented so it should not be part\n of the value") So(testData.Value3, ShouldEqual, `. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Eu consequat ac felis donec et odio pellentesque diam volutpat. Mauris commodo quis imperdiet massa tincidunt nunc. Interdum velit euismod in pellentesque. Nisl condimentum id venenatis a condimentum vitae sapien pellentesque. Nascetur ridiculus mus mauris vitae. Posuere urna nec tincidunt praesent semper feugiat. Lorem donec massa sapien faucibus et molestie ac feugiat sed. Ipsum dolor sit amet consectetur adipiscing elit. Enim sed faucibus turpis in eu mi. A diam sollicitudin tempor id. Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit. diff --git a/parser.go b/parser.go index b8b5aa8..ca76f5f 100644 --- a/parser.go +++ b/parser.go @@ -302,7 +302,6 @@ func (p *parser) readPythonMultilines(line string, bufferSize int) (string, erro parserBufferPeekResult, _ := p.buf.Peek(bufferSize) peekBuffer := bytes.NewBuffer(parserBufferPeekResult) - indentSize := 0 for { peekData, peekErr := peekBuffer.ReadBytes('\n') if peekErr != nil { @@ -329,19 +328,6 @@ func (p *parser) readPythonMultilines(line string, bufferSize int) (string, erro return line, nil } - // Determine indent size and line prefix. - currentIndentSize := len(peekMatches[1]) - if indentSize < 1 { - indentSize = currentIndentSize - p.debug("readPythonMultilines: indent size is %d", indentSize) - } - - // Make sure each line is indented at least as far as first line. - if currentIndentSize < indentSize { - p.debug("readPythonMultilines: end of value, current indent: %d, expected indent: %d, line: %q", currentIndentSize, indentSize, line) - return line, nil - } - // Advance the parser reader (buffer) in-sync with the peek buffer. _, err := p.buf.Discard(len(peekData)) if err != nil { @@ -349,8 +335,7 @@ func (p *parser) readPythonMultilines(line string, bufferSize int) (string, erro return "", err } - // Handle indented empty line. - line += "\n" + peekMatches[1][indentSize:] + peekMatches[2] + line += "\n" + peekMatches[0] } }