json.loads() stupidly does not accept memoryview

This commit is contained in:
Kovid Goyal
2023-11-07 17:24:02 +05:30
parent 50935b6c93
commit 5c9aa6a21a
2 changed files with 4 additions and 2 deletions

View File

@@ -775,7 +775,7 @@ class Boss:
cmd_prefix = b'\x1bP@kitty-cmd'
terminator = b'\x1b\\'
if msg_bytes.startswith(cmd_prefix) and msg_bytes.endswith(terminator):
cmd = memoryview(msg_bytes[len(cmd_prefix):-len(terminator)])
cmd = memoryview(msg_bytes)[len(cmd_prefix):-len(terminator)]
response = self._handle_remote_command(cmd, peer_id=peer_id)
if response is None:
return None

View File

@@ -53,8 +53,10 @@ def encode_response_for_peer(response: Any) -> bytes:
def parse_cmd(serialized_cmd: memoryview, encryption_key: EllipticCurveKey) -> Dict[str, Any]:
# See https://github.com/python/cpython/issues/74379 for why we cant use
# memoryview directly :((
try:
pcmd = json.loads(serialized_cmd)
pcmd = json.loads(bytes(serialized_cmd))
except Exception:
return {}
if not isinstance(pcmd, dict) or 'version' not in pcmd: