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

New lines in multi-line strings trimmed incorrectly #417

Open
KaneGreen opened this issue Mar 23, 2023 · 0 comments
Open

New lines in multi-line strings trimmed incorrectly #417

KaneGreen opened this issue Mar 23, 2023 · 0 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

@KaneGreen
Copy link

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'}
@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 1, 2023
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

2 participants