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

Broken parsing of triple-quoted strings with dotted keys #265

Open
miccoli opened this issue Oct 31, 2019 · 1 comment · May be fixed by #279
Open

Broken parsing of triple-quoted strings with dotted keys #265

miccoli opened this issue Oct 31, 2019 · 1 comment · May be fixed by #279
Labels
component: decoder Related to parsing in `toml.load` syntax: strings Related to string literals type: bug A confirmed bug or unintended behavior

Comments

@miccoli
Copy link

miccoli commented Oct 31, 2019

I found another problem with triple quoted strings that seems not to be covered in related open bugs (#123, #230, #237).

>>> print(toml.__version__)
0.10.0
>>> test = 'a.b = """123\n"""'
>>> print(test)
a.b = """123
"""
>>> toml.loads(test)
{'a': {}, 'b': '123\n'}

but I would expect {'a': {'b': '123\n'}}

Note that it is the newline inside the triple-quoted string that triggers this error:

>>> test2 = 'a.b = """123"""'
>>> toml.loads(test2)
{'a': {'b': '123'}}
@samuelcolvin
Copy link

This seems like quite a significant issue. Any chance of fixing it?

import toml

s1 = '''
foo.bar= "hello"
'''
print(toml.loads(s1))
#> {'foo': {'bar': 'hello'}} --- correct

s2 = '''
foo.bar= """
hello"""
'''
print(toml.loads(s2))
#> {'foo': {'bar': 'hello'}} --- correct

s3 = '''
foo.bar= """
hello
"""
'''
print(toml.loads(s3))
#> {'foo': {}, 'bar': 'hello\n'} --- this is wrong !!!

s4 = '''
foo.bar= """
hello

more"""
'''
print(toml.loads(s4))
#> {'foo': {}, 'bar': 'hello\n\nmore'} --- this is wrong !!!

samuelcolvin added a commit to samuelcolvin/toml that referenced this issue Jan 7, 2020
samuelcolvin added a commit to samuelcolvin/toml that referenced this issue Jan 7, 2020
@samuelcolvin samuelcolvin linked a pull request Jan 7, 2020 that will close this issue
eliwaksbaum added a commit to eliwaksbaum/toml that referenced this issue Oct 25, 2021
eliwaksbaum added a commit to eliwaksbaum/toml that referenced this issue Oct 25, 2021
@pradyunsg pradyunsg added type: bug A confirmed bug or unintended behavior 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

Successfully merging a pull request may close this issue.

3 participants