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

Incorrect toml.dumps() value when "\\x" is present in the string #261

Open
wbenny opened this issue Oct 19, 2019 · 2 comments
Open

Incorrect toml.dumps() value when "\\x" is present in the string #261

wbenny opened this issue Oct 19, 2019 · 2 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

@wbenny
Copy link

wbenny commented Oct 19, 2019

Current behavior:

>>> toml.dumps({ 'val': 'win32\\path\\x64\\file.txt'})
'val = "win32\\path\\x64\\\\file.txt"\n'  # note the \\\\ after x64

Correct behavior:

toml.dumps({ 'val': 'win32\\path\\x64\\file.txt'})
'val = "win32\\path\\x64\\file.txt"\n'

I suspect the bug occurs somewhere here: https://github.com/uiri/toml/blob/master/toml/encoder.py#L98

@wbenny
Copy link
Author

wbenny commented Oct 19, 2019

This dirty fix appears to work, but I'm not 100% sure that it won't break anything else:

    #v = v.split("\\x")
    v = re.split(r'(?<!\\)\\x', v)

@wbenny
Copy link
Author

wbenny commented Oct 19, 2019

Possibly linked with #201

@pradyunsg pradyunsg added component: encoder Related to serialising in `toml.dump` type: bug A confirmed bug or unintended behavior syntax: strings Related to string literals labels Apr 20, 2022
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