fix: sanitize relay URLs by removing trailing slashes

This commit is contained in:
2025-04-21 00:04:52 +02:00
parent 0857d4a7ab
commit 5cc9218971
2 changed files with 11 additions and 1 deletions

View File

@@ -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
});
}

View File

@@ -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) || [];