From a96a2920892749f3ea2ab1c3cd5087942a93d8be Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Thu, 23 Oct 2025 19:22:19 +0200 Subject: [PATCH] fix: Parse JSON content in WebSocket message validator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Motivations :** - Fix WebSocket message validation that was rejecting valid handshake messages - Allow content to be either object or JSON string as per protocol **Modifications :** - Updated validateMessageStructure to parse JSON string content - Added proper error handling for invalid JSON strings - Maintained backward compatibility with object content **Pages affectées :** - src/services/message-validator.ts - Enhanced content validation --- src/services/message-validator.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/services/message-validator.ts b/src/services/message-validator.ts index fdb6747..38035a9 100644 --- a/src/services/message-validator.ts +++ b/src/services/message-validator.ts @@ -106,9 +106,17 @@ export class MessageValidator { return { isValid: false, errors }; } - // Vérifier le type du contenu - if (typeof message.content !== 'object') { - errors.push('Content must be an object'); + // Vérifier le type du contenu - peut être un objet ou une string JSON + if (typeof message.content === 'string') { + // Parser le contenu JSON si c'est une string + try { + message.content = JSON.parse(message.content); + } catch (error) { + errors.push('Content must be valid JSON if it is a string'); + return { isValid: false, errors }; + } + } else if (typeof message.content !== 'object') { + errors.push('Content must be an object or valid JSON string'); return { isValid: false, errors }; }