Skip to content

Commit b277474

Browse files
committed
fix: escape backslashes in basic strings
Resolve #245
1 parent 903c2e9 commit b277474

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

tests/test_items.py

+8
Original file line numberDiff line numberDiff line change
@@ -887,3 +887,11 @@ def test_copy_copy():
887887
classifiers = result["tool"]["poetry"]["classifiers"]
888888
new = copy.copy(classifiers)
889889
assert new == classifiers
890+
891+
892+
@pytest.mark.parametrize(
893+
"key_str,escaped",
894+
[("\\", '"\\\\"'), ('"', '"\\""'), ("\t", '"\\t"'), ("\x10", '"\\u0010"')],
895+
)
896+
def test_escape_key(key_str, escaped):
897+
assert api.key(key_str).as_string() == escaped

tomlkit/_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def parse_rfc3339(string: str) -> Union[datetime, date, time]:
113113
**{v: f"\\{k}" for k, v in _escaped.items()},
114114
'"""': '""\\"',
115115
}
116-
_basic_escapes = CONTROL_CHARS | {'"'}
116+
_basic_escapes = CONTROL_CHARS | {'"', "\\"}
117117

118118

119119
def _unicode_escape(seq: str) -> str:

0 commit comments

Comments
 (0)