toml icon indicating copy to clipboard operation
toml copied to clipboard

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

Open wbenny opened this issue 5 years ago • 2 comments

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 avatar Oct 19 '19 12:10 wbenny

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 avatar Oct 19 '19 12:10 wbenny

Possibly linked with https://github.com/uiri/toml/issues/201

wbenny avatar Oct 19 '19 12:10 wbenny