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 parsing python multiline string #299

Merged
merged 1 commit into from Nov 28, 2021

Conversation

gandarez
Copy link
Contributor

@gandarez gandarez commented Sep 6, 2021

What problem should be fixed?

This PR fixes parsing Python multiline strings to keep the original indentation instead of removing all leading spaces. It breaks some compatibility with legacy Python parsers as them fail to parse multiline strings that are malformed. This issue was first reported here.

Have you added test cases to catch the problem?

Yes

@gandarez
Copy link
Contributor Author

gandarez commented Sep 9, 2021

@unknwon any update here?

@unknwon
Copy link
Member

unknwon commented Sep 9, 2021

Thanks for the PR! Will take a look when time permits.

Comment on lines -332 to -344
// 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
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the rationale of deleting these lines? Without these, it seems we can't determine indent size for the multiline value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main idea here is to not bypass any miss indentation from the source which means we're looking for break lines and not for "malformed" multiline values. Having it in the logic makes the first line to always determine the other's indentation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main idea here is to not bypass any miss indentation from the source which means we're looking for break lines and not for "malformed" multiline values. Having it in the logic makes the first line to always determine the other's indentation.

What is definition of a "break line", is it a line that failed to be matched with pythonMultiline.FindStringSubmatch?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All look good to me, just want to confirm the impact of deleting these lines.

@unknwon unknwon added status: needs feedback Needs more feedback to proceed status: reviewed The pull request has been reviewed labels Sep 20, 2021
@gandarez
Copy link
Contributor Author

Hi, any update on this?

@bryanpedini
Copy link
Contributor

Hi, any update on this?

From the history of the comments in @unknwon's review, it seems he's waiting for some clarifications from your side on the deleted lines.

@gandarez
Copy link
Contributor Author

The detailed explanatation for this issue was first reported here. In a nutshell it's removing the original indentation when saving.

@unknwon
Copy link
Member

unknwon commented Nov 27, 2021

@gandarez LGTM! Could you fix the conflicts so CI can be kicked off?

@unknwon unknwon removed the status: needs feedback Needs more feedback to proceed label Nov 28, 2021
@codecov
Copy link

codecov bot commented Nov 28, 2021

Codecov Report

Merging #299 (cdc3c1c) into main (c2f10d6) will increase coverage by 0.15%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #299      +/-   ##
==========================================
+ Coverage   88.13%   88.28%   +0.15%     
==========================================
  Files           9        9              
  Lines        1357     1349       -8     
==========================================
- Hits         1196     1191       -5     
+ Misses         98       96       -2     
+ Partials       63       62       -1     

@unknwon unknwon merged commit e641746 into go-ini:main Nov 28, 2021
@unknwon
Copy link
Member

unknwon commented Nov 28, 2021

https://github.com/go-ini/ini/releases/tag/v1.65.0 has been tagged for this merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: reviewed The pull request has been reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants