From 50a02e8dfde846c44464e21859d08cb7500112ad Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Fri, 14 Jun 2024 04:04:00 -0400 Subject: [PATCH] topic validation for the join box --- app.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index eb6a1f6..cacbaa7 100644 --- a/app.js +++ b/app.js @@ -369,7 +369,15 @@ async function createChatRoom() { async function joinChatRoom(e) { e.preventDefault(); - const topicStr = document.querySelector('#join-chat-room-topic').value; + const topicStr = document.querySelector('#join-chat-room-topic').value.trim(); + + // Validate the topic string + const isValidTopic = /^[0-9a-fA-F]{64}$/.test(topicStr); + if (!isValidTopic) { + alert('Invalid topic format. Please enter a 64-character hexadecimal string.'); + return; + } + const topicBuffer = b4a.from(topicStr, 'hex'); addRoomToList(topicStr); await joinSwarm(topicBuffer);