From 5cc9218971e1d29ef59cb88d4bcafc543b00395a Mon Sep 17 00:00:00 2001 From: highperfocused Date: Mon, 21 Apr 2025 00:04:52 +0200 Subject: [PATCH] fix: sanitize relay URLs by removing trailing slashes --- app/layout.tsx | 7 ++++++- components/AddRelaySheet.tsx | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/layout.tsx b/app/layout.tsx index f310c58..9e043cb 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -29,9 +29,14 @@ export default function RootLayout({ try { const customRelays = JSON.parse(localStorage.getItem("customRelays") || "[]"); if (customRelays.length > 0) { + // Remove trailing slashes from any relay URLs + const sanitizedRelays = customRelays.map((relay: string) => + relay.endsWith('/') ? relay.slice(0, -1) : relay + ); + setRelayUrls(prevRelays => { // Combine default relays with custom relays, removing duplicates - const allRelays = [...prevRelays, ...customRelays]; + const allRelays = [...prevRelays, ...sanitizedRelays]; return Array.from(new Set(allRelays)); // Remove duplicates }); } diff --git a/components/AddRelaySheet.tsx b/components/AddRelaySheet.tsx index 2be0f6c..1ae0768 100644 --- a/components/AddRelaySheet.tsx +++ b/components/AddRelaySheet.tsx @@ -34,6 +34,11 @@ export function AddRelaySheet({ onRelayAdded }: AddRelaySheetProps) { if (!formattedUrl.startsWith("wss://")) { formattedUrl = `wss://${formattedUrl}`; } + + // Remove trailing slash if present + if (formattedUrl.endsWith('/')) { + formattedUrl = formattedUrl.slice(0, -1); + } // Check if relay already exists in connected relays const existingRelays = connectedRelays?.map(relay => relay.url) || [];