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

Parsing fails on multiline string with comments and newlines #204

Open
ghost opened this issue Oct 4, 2018 · 3 comments
Open

Parsing fails on multiline string with comments and newlines #204

ghost opened this issue Oct 4, 2018 · 3 comments
Labels
component: decoder Related to parsing in `toml.load` syntax: strings Related to string literals type: bug A confirmed bug or unintended behavior

Comments

@ghost
Copy link

ghost commented Oct 4, 2018

I can't put my finger on this exactly, but it seems that the parser gets confused by certain combinations of multiline strings with comments.

For example:

toml.loads('a = """#\n"""#')

returns {}
while it should return {"a": "#\n"}

May be related to #152.

@uiri uiri changed the title Parsing fails on multiline string with comments Parsing fails on multiline string with comments and newlines Oct 5, 2018
@uiri
Copy link
Owner

uiri commented Oct 5, 2018

Thank you for the bug report!

Your example appears to be equivalent to the following toml document:

a = """#
"""#

Is this correct?

This appears to be an issue of combining # and newlines in the same multiline string.

@uiri uiri added the bug label Oct 5, 2018
@ghost
Copy link
Author

ghost commented Oct 5, 2018

Yes I agree. That is the TOML document I'm talking about.

Indeed it looks like certain combinations do not work well inside the multiline string.
Note however that the second comment (immediately after the multiline string) is also necessary to trigger the problem. That puzzles me.

rudy-6-4 added a commit to rudy-6-4/toml that referenced this issue May 5, 2020
rudy-6-4 added a commit to rudy-6-4/toml that referenced this issue May 5, 2020
triple quote """ or ''' ending a multiline string are not checked
correctly if line ends with comments or spacing or anything
@rudy-6-4
Copy link

rudy-6-4 commented May 7, 2020

This issues is due to '# ' or any chracter (e.g. space )just after """. The check for """ is done on the non stripped version of the line.
'#' is replaced by a space during a preprocessing step and later the space is not removed when operating in multistring mode.

rudy-6-4 added a commit to rudy-6-4/toml that referenced this issue May 8, 2020
triple quote """ or ''' ending a multiline string are not checked
correctly if line ends with comments or spacing or anything
@pradyunsg pradyunsg added type: bug A confirmed bug or unintended behavior and removed bug labels Mar 13, 2022
@pradyunsg pradyunsg added component: decoder Related to parsing in `toml.load` syntax: strings Related to string literals labels Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: decoder Related to parsing in `toml.load` syntax: strings Related to string literals type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants