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

Error when encoding strings which contain control characters #246

Open
erkyrath opened this issue Apr 29, 2019 · 1 comment
Open

Error when encoding strings which contain control characters #246

erkyrath opened this issue Apr 29, 2019 · 1 comment
Labels
component: encoder Related to serialising in `toml.dump` syntax: strings Related to string literals type: bug A confirmed bug or unintended behavior

Comments

@erkyrath
Copy link
Contributor

>>> toml.dumps({"a": "\x01"})

Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.7/site-packages/toml/encoder.py", line 47, in dumps
addtoretval, sections = encoder.dump_sections(o, "")
File "/usr/local/lib/python3.7/site-packages/toml/encoder.py", line 209, in dump_sections
unicode(self.dump_value(o[section])) + '\n')
File "/usr/local/lib/python3.7/site-packages/toml/encoder.py", line 160, in dump_value
return dump_fn(v) if dump_fn is not None else self.dump_funcsstr
File "/usr/local/lib/python3.7/site-packages/toml/encoder.py", line 94, in _dump_str
v = [v[0] + joiner + v[1]] + v[2:]
IndexError: list index out of range

This value can be represented in TOML, and in fact the library is able to decode it correctly:

>>> toml.loads( r'a = "\u0001"' )
{'a': '\x01'}

But this input can't be round-tripped:

>>> toml.dumps(toml.loads( r'a = "\u0001"' ))

(same stack trace)

@erkyrath
Copy link
Contributor Author

#201 looks related; the pull request on that issue may fix this.

@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