Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent onBlur from appending URL scheme to URLs #2449

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lemmy-translations
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remember to update translations to their latest versions before the 0.19.4 release.

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