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

more and more backslashes when repeatedly dump and load #441

Open
Difocd opened this issue Jun 4, 2024 · 1 comment
Open

more and more backslashes when repeatedly dump and load #441

Difocd opened this issue Jun 4, 2024 · 1 comment

Comments

@Difocd
Copy link

Difocd commented Jun 4, 2024

When I dump something contains backslash to file and then load it, there are double backslashes. Like the below:

import toml

with open('test.toml', 'w', encoding='utf-8') as f:
    toml.dump({"c:\\test": {}}, f)

for _ in range(5):
    with open('test.toml', encoding='utf-8') as f:
        contents = toml.load(f)
    print(contents)
    with open('test.toml', 'w', encoding='utf-8') as f:
        toml.dump(contents, f)

This will print:

{'c:\\\\test': {}}
{'c:\\\\\\\\test': {}}
{'c:\\\\\\\\\\\\\\\\test': {}}
{'c:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\test': {}}
{'c:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\test': {}}

I don't know if this is a bug or just a feature. If this is a feature, how can I avoid this?

@ArsThaumaturgis
Copy link

I've just bumped into this--or something much like it--myself.

Specifically, it looks to me like TOML, when presented with a backslash (whether alone or escaped), outputs two backslashes in its place.

For example, the following program:

import toml

mew = "cat = 'this is a \ test'"
result = toml.loads(mew)
print (result)

produces the following output on my machine:
{'cat': 'this is a \\ test'}

Note that the single backslash has become a double backslash.

TOML version: 1.10.2, I believe
OS: Ubuntu Linux 22.04.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants