toml
toml copied to clipboard
New lines in multi-line strings trimmed incorrectly
This is similar to #68, but a little different.
In multiline strings, any newlines immediately following the delimiter are trimmed. But according to the TOML specification, if there is at least one newline character, only the first one is trimmed.
TOML spec v1.0.0 says:
A newline immediately following the opening delimiter will be trimmed. All other whitespace and newline characters remain intact.
It is "A newline", not "newlines" or "all new line".
The following example shows the case of multi-line basic strings ("""
), but the same applies to multi-line literal strings ('''
).
Example
import toml # version: 0.10.2
example = "first\nsecond"
for i in range(5):
print(toml.loads('s = """{}"""'.format(example)))
example = "\n" + example
EXPECTED OUTPUT:
{'s': 'first\nsecond'}
{'s': 'first\nsecond'}
{'s': '\nfirst\nsecond'}
{'s': '\n\nfirst\nsecond'}
{'s': '\n\n\nfirst\nsecond'}
ACTUAL OUTPUT:
{'s': 'first\nsecond'}
{'s': 'first\nsecond'}
{'s': 'first\nsecond'}
{'s': 'first\nsecond'}
{'s': 'first\nsecond'}