From e66f997853758fd6f7b48ac5962a9819844229fd Mon Sep 17 00:00:00 2001 From: PatMulligan <43773168+PatMulligan@users.noreply.github.com> Date: Mon, 15 Sep 2025 12:42:33 +0200 Subject: [PATCH] FIX: Ensure valid json (#39) * Build EVENT message with json.dumps instead of string interpolation Ensures outbound Nostr messages are valid JSON and safely escaped by constructing the payload as Python objects and serializing with json.dumps * improve logs * remove log causing check failure --- router.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/router.py b/router.py index 966705a..a7054e9 100644 --- a/router.py +++ b/router.py @@ -111,10 +111,14 @@ class NostrRouter: # this reconstructs the original response from the relay # reconstruct original subscription id s_original = self.original_subscription_ids[s] - event_to_forward = f"""["EVENT", "{s_original}", {event_json}]""" + event_to_forward = json.dumps( + ["EVENT", s_original, json.loads(event_json)] + ) await self.websocket.send_text(event_to_forward) except Exception as e: - logger.debug(e) # there are 2900 errors here + logger.warning( + f"[NOSTRCLIENT] Error in _handle_received_subscription_events: {e}" + ) def _handle_notices(self): while len(NostrRouter.received_subscription_notices):