Prevent onBlur from appending URL scheme to URLs (#2449)

This commit is contained in:
SleeplessOne1917 2024-05-07 13:21:16 -04:00 committed by GitHub
parent 167d5c991e
commit ef72c75000
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

@ -1 +1 @@
Subproject commit 866e4056656755f7b31e20094b46391e6931e3e7 Subproject commit b2de37b31ea6294fdcd7f41492ea241b62ee9099

View file

@ -14,6 +14,12 @@ function handleTextChange(i: UrlListTextarea, event: any) {
i.setState({ text: event.target.value }); 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) { function handleTextBlur(i: UrlListTextarea, event: any) {
const inputValue: string = event.currentTarget?.value ?? ""; const inputValue: string = event.currentTarget?.value ?? "";
@ -24,10 +30,10 @@ function handleTextBlur(i: UrlListTextarea, event: any) {
let url: string; let url: string;
try { try {
url = new URL(str).toString(); url = processUrl(str);
} catch { } catch {
try { try {
url = new URL("https://" + str).toString(); url = processUrl(URL_SCHEME + str);
} catch { } catch {
continue; continue;
} }