toml icon indicating copy to clipboard operation
toml copied to clipboard

Brackets in multiline literals broken

Open darvid opened this issue 7 years ago • 1 comments

I can't seem to find a ticket or anything in the spec that would explain this behavior. I'm using TOML as the format for a configuration file which will store a large number of regular expressions in multiline literals. One of these expressions contains a character class with a single quote, and causes all values from the affected group to be lost.

I could reproduce this behavior by using a multiline literal in combination with newlines either at the end of the multiline literal or at the end of the TOML configuration file. This is the weird part: either the multiline literal or the actual TOML input can have a trailing newline, but not both.

# {'foo': {'bar': "[']"}}
[foo]
bar = '''[']'''

# {'foo': {}}
[foo]
bar = '''
[']
'''

# {'foo': {'bar': "[']"}} UNLESS TOML input ends in a newline
[foo]
bar = '''
[']'''

I just thought this behavior was incredibly strange. ~The workaround of course is to strip newlines from all input before it's parsed, and to ensure any multiline literals do not have trailing newlines.~

Actually, the behavior gets weirder: any keys after the value with the single quote surrounded by brackets get eaten:

# {'foo': {'bar': "[']'''baz = '''qux"}}
bar = '''
[']'''
baz = '''
qux'''

darvid avatar Feb 23 '18 18:02 darvid

Hi David,

Thank you for the thorough and detailed bug report. It appears that fixes for other bugs have made this behaviour a little bit weirder.

Your last example is now always {u'foo': {u'bar': u"[']"}} but your middle example is still {u'foo': {}} with a trailing newline at the end of the configuration input, but {u'foo': {u'bar': u"[']\n"}} if there is no trailing newline after the multiline literal string is closed...

I will keep looking into it, as time permits.

uiri avatar Nov 27 '18 07:11 uiri