Skip to content

Commit f8d697a

Browse files
committed
Fix string regex
1 parent 93e4306 commit f8d697a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Lib/json/tool.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def main():
8383

8484

8585
color_pattern = re.compile(r'''
86-
(?P<string>"(\\"|[^"])*?") | # String
87-
(?P<number>[\d\-+.Ee]+) | # Number
88-
(?P<boolean>true|false) | # Boolean
89-
(?P<null>null) # Null
86+
(?P<string>"(\\.|[^"\\])*?") | # String
87+
(?P<number>[\d\-+.Ee]+) | # Number
88+
(?P<boolean>true|false) | # Boolean
89+
(?P<null>null) # Null
9090
''', re.VERBOSE)
9191

9292

Lib/test/test_json/test_tool.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,16 @@ def test_colors(self):
268268
(r'" \"foo\" "', b'\x1b[32m" \\"foo\\" "\x1b[0m'),
269269
('123', b'\x1b[33m123\x1b[0m'),
270270
('-1.2345e+23', b'\x1b[33m-1.2345e+23\x1b[0m'),
271+
(r'{"\\": ""}',
272+
b'''\
273+
{
274+
\x1b[32m"\\\\"\x1b[0m: \x1b[32m""\x1b[0m
275+
}'''),
276+
(r'{"\\\\": ""}',
277+
b'''\
278+
{
279+
\x1b[32m"\\\\\\\\"\x1b[0m: \x1b[32m""\x1b[0m
280+
}'''),
271281
('{"foo": "bar", "baz": 1234, "qux": [true, false, null]}',
272282
b'''\
273283
{

0 commit comments

Comments
 (0)