Skip to content

Commit

Permalink
fix: escape backslashes in basic strings
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Oct 27, 2022
1 parent 559ce53 commit 83d9edb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,3 +887,11 @@ def test_copy_copy():
classifiers = result["tool"]["poetry"]["classifiers"]
new = copy.copy(classifiers)
assert new == classifiers


@pytest.mark.parametrize(
"key_str,escaped",
[("\\", '"\\\\"'), ('"', '"\\""'), ("\t", '"\\t"'), ("\x10", '"\\u0010"')],
)
def test_escape_key(key_str, escaped):
assert api.key(key_str).as_string() == escaped
2 changes: 1 addition & 1 deletion tomlkit/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def parse_rfc3339(string: str) -> Union[datetime, date, time]:
**{v: f"\\{k}" for k, v in _escaped.items()},
'"""': '""\\"',
}
_basic_escapes = CONTROL_CHARS | {'"'}
_basic_escapes = CONTROL_CHARS | {'"', "\\"}


def _unicode_escape(seq: str) -> str:
Expand Down

0 comments on commit 83d9edb

Please sign in to comment.