mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-22 19:01:26 +00:00
Prevent onBlur from appending URL scheme to URLs (#2449)
This commit is contained in:
parent
167d5c991e
commit
ef72c75000
2 changed files with 9 additions and 3 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 866e4056656755f7b31e20094b46391e6931e3e7
|
||||
Subproject commit b2de37b31ea6294fdcd7f41492ea241b62ee9099
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue