8000 gh-125660: Python implementation of `json.loads()` accepts invalid unicode escapes by nineteendo · Pull Request #125683 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-125660: Python implementation of json.loads() accepts invalid unicode escapes #125683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Reject invalid unicode escapes
  • Loading branch information
nineteendo authored Oct 18, 2024
commit a40d52201639c82ec3f15e8795f8c83897deb9b5
8 changes: 4 additions & 4 deletions Lib/json/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ def __reduce__(self):
}


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):
if match := _m(s, end):
try:
return int(esc, 16)
return int(match.group(), 16)
except ValueError:
pass
msg = "Invalid \\uXXXX escape"
Expand Down
Loading
0