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

Default TomlEncoder does not escape backslashes correctly #415

Open
Poofjunior opened this issue Mar 13, 2023 · 0 comments
Open

Default TomlEncoder does not escape backslashes correctly #415

Poofjunior opened this issue Mar 13, 2023 · 0 comments
Labels
component: encoder Related to serialising in `toml.dump` syntax: strings Related to string literals type: bug A confirmed bug or unintended behavior

Comments

@Poofjunior
Copy link

This is mainly an issue storing windows file paths.

In a nutshell, a config containing this data:

# config.toml
[specs]
my_path = "C:\\Program Files\\Euresys\\Memento\\bin\\x86_64\\memento.exe" 

can be loaded with:

cfg = toml.load("config.toml")

and then saved with:

with open("new_config.toml", 'w') as f:
    f.write(toml.dumps(cfg))

But the result will remove the first two double backslashes for some characters that can be incorrectly parsed as valid.

# new_config.toml
[specs]
my_path = "C:\Program Files\Euresys\Memento\bin\x86_64\\memento.exe"  

It looks like the double-backslash is not recognized when the next character forms a valid unicode shorthand?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: encoder Related to serialising in `toml.dump` 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