Skip to content

Commit 12314bd

Browse files
authored
TOML 1.1: Add \xHH Unicode escape code to basic strings (#202)
1 parent 2a2aa62 commit 12314bd

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/tomli/_parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,8 @@ def parse_basic_str_escape(
580580
pos += 1
581581
pos = skip_chars(src, pos, TOML_WS_AND_NEWLINE)
582582
return pos, ""
583+
if escape_id == "\\x":
584+
return parse_hex_char(src, pos, 2)
583585
if escape_id == "\\u":
584586
return parse_hex_char(src, pos, 4)
585587
if escape_id == "\\U":
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
{"escape":
2-
{"type":"string","value":"\u001B"}}
1+
{
2+
"escape": {"type":"string","value":"\u001B"},
3+
"tab": {"type":"string","value":"\t"},
4+
"upper-j": {"type":"string","value":"J"},
5+
"upper-j-2": {"type":"string","value":"J"}
6+
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
escape = "\e"
1+
escape = "\e"
2+
tab = "\x09"
3+
upper-j = "\x4a"
4+
upper-j-2 = "\x4A"

tests/test_data.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ def test_valid(self):
4646
# compatible with yet.
4747
if valid.stem in {
4848
"no-seconds",
49-
"hex-escape",
5049
"common-34",
5150
"common-31",
5251
"common-29",
53-
"common-12",
5452
}:
5553
with self.assertRaises(tomllib.TOMLDecodeError):
5654
tomllib.loads(toml_str)

0 commit comments

Comments
 (0)