Skip to content

Commit

Permalink
Prevent onBlur from appending URL scheme to URLs (#2449)
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessOne1917 authored May 7, 2024
1 parent 167d5c9 commit ef72c75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lemmy-translations
10 changes: 8 additions & 2 deletions src/shared/components/common/url-list-textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "";

Expand All @@ -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;
}
Expand Down

0 comments on commit ef72c75

Please sign in to comment.