From ef72c750007191444e4b46afa24107e42e26208d Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> Date: Tue, 7 May 2024 13:21:16 -0400 Subject: [PATCH] Prevent onBlur from appending URL scheme to URLs (#2449) --- lemmy-translations | 2 +- src/shared/components/common/url-list-textarea.tsx | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lemmy-translations b/lemmy-translations index 866e4056..b2de37b3 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit 866e4056656755f7b31e20094b46391e6931e3e7 +Subproject commit b2de37b31ea6294fdcd7f41492ea241b62ee9099 diff --git a/src/shared/components/common/url-list-textarea.tsx b/src/shared/components/common/url-list-textarea.tsx index 5063e101..8c6b6bea 100644 --- a/src/shared/components/common/url-list-textarea.tsx +++ b/src/shared/components/common/url-list-textarea.tsx @@ -14,6 +14,12 @@ function handleTextChange(i: UrlListTextarea, event: any) { i.setState({ text: event.target.value }); } +const URL_SCHEME = "https://"; + +function processUrl(str: string) { + return new URL(str).toString().replace(URL_SCHEME, ""); +} + function handleTextBlur(i: UrlListTextarea, event: any) { const inputValue: string = event.currentTarget?.value ?? ""; @@ -24,10 +30,10 @@ function handleTextBlur(i: UrlListTextarea, event: any) { let url: string; try { - url = new URL(str).toString(); + url = processUrl(str); } catch { try { - url = new URL("https://" + str).toString(); + url = processUrl(URL_SCHEME + str); } catch { continue; }