mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
[3.13] gh-125660: Reject invalid unicode escapes for Python implementation of JSON decoder (GH-125683) (GH-125694)
(cherry picked from commit df751363e3
)
Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
This commit is contained in:
parent
6715afe349
commit
d9dafc790d
3 changed files with 16 additions and 4 deletions
|
@ -50,17 +50,18 @@ _CONSTANTS = {
|
|||
}
|
||||
|
||||
|
||||
HEXDIGITS = re.compile(r'[0-9A-Fa-f]{4}', FLAGS)
|
||||
STRINGCHUNK = re.compile(r'(.*?)(["\\\x00-\x1f])', FLAGS)
|
||||
BACKSLASH = {
|
||||
'"': '"', '\\': '\\', '/': '/',
|
||||
'b': '\b', 'f': '\f', 'n': '\n', 'r': '\r', 't': '\t',
|
||||
}
|
||||
|
||||
def _decode_uXXXX(s, pos):
|
||||
esc = s[pos + 1:pos + 5]
|
||||
if len(esc) == 4 and esc[1] not in 'xX':
|
||||
def _decode_uXXXX(s, pos, _m=HEXDIGITS.match):
|
||||
esc = _m(s, pos + 1)
|
||||
if esc is not None:
|
||||
try:
|
||||
return int(esc, 16)
|
||||
return int(esc.group(), 16)
|
||||
except ValueError:
|
||||
pass
|
||||
msg = "Invalid \\uXXXX escape"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue