Skip to content

Commit

Permalink
Add \xHH Unicode escape code to basic strings
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin committed Aug 5, 2022
1 parent 7e563ee commit 2b195e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/tomli/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def parse_inline_table(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos
pos = skip_chars(src, pos, TOML_WS)


def parse_basic_str_escape(
def parse_basic_str_escape( # noqa: C901
src: str, pos: Pos, *, multiline: bool = False
) -> tuple[Pos, str]:
escape_id = src[pos : pos + 2]
Expand All @@ -484,6 +484,8 @@ def parse_basic_str_escape(
pos += 1
pos = skip_chars(src, pos, TOML_WS_AND_NEWLINE)
return pos, ""
if escape_id == "\\x":
return parse_hex_char(src, pos, 2)
if escape_id == "\\u":
return parse_hex_char(src, pos, 4)
if escape_id == "\\U":
Expand Down
5 changes: 5 additions & 0 deletions tests/data/valid/multiline-basic-str/replacements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tab": {"type":"string","value":"\t"},
"upper-j": {"type":"string","value":"J"},
"upper-j-2": {"type":"string","value":"J"}
}
3 changes: 3 additions & 0 deletions tests/data/valid/multiline-basic-str/replacements.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tab = "\x09"
upper-j = "\x4a"
upper-j-2 = "\x4A"

0 comments on commit 2b195e3

Please sign in to comment.