toml icon indicating copy to clipboard operation
toml copied to clipboard

Bug with dotted keys and multi-line strings

Open LukasVik opened this issue 3 years ago • 2 comments

Hello,

I suspect there is a bug when parsing multi-line strings in dotted-key tables.

import toml

print(toml.__version__)
print()

toml_data = """
[a]

description = "AAA"

b.description = "BBB"
"""
toml_dict = toml.loads(toml_data)

print(toml_dict["a"]["description"])
print(toml_dict["a"]["b"]["description"])
print()


toml_data = '''
[a]

description = "AAA"

b.description = """
BBB
"""
'''
toml_dict = toml.loads(toml_data)

print(toml_dict["a"]["description"])
print(toml_dict["a"]["b"]["description"])

Gives the output

$ python3 toml_mwe.py 
0.10.2

AAA
BBB

BBB

Traceback (most recent call last):
  File "toml_mwe.py", line 30, in <module>
    print(toml_dict["a"]["b"]["description"])
KeyError: 'description'

Whereas I would expect

AAA
BBB

for both cases.

LukasVik avatar Apr 01 '21 13:04 LukasVik

Just ran into this myself. Anyone know how to fix this? I dug a little into the code around here but it was not clear what (if anything) could be done.

eugene-bulkin avatar Aug 09 '21 18:08 eugene-bulkin

@eugene-bulkin This package does not appear to be maintained anymore. I moved on to use the tomlkit package instead which has worked well for me: https://pypi.org/project/tomlkit/

LukasVik avatar Aug 10 '21 05:08 LukasVik