From ef2abf824ea3bcd8fcf1b5379f1b0bfe3ded7c28 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 22 Jul 2022 00:23:53 +0100 Subject: [PATCH] fix: Correctly sanitize href in link editor 'open url' flow --- app/editor/components/LinkEditor.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/editor/components/LinkEditor.tsx b/app/editor/components/LinkEditor.tsx index 02e497e60321..f444f6279c62 100644 --- a/app/editor/components/LinkEditor.tsx +++ b/app/editor/components/LinkEditor.tsx @@ -44,7 +44,7 @@ type Props = { href: string, event: React.MouseEvent ) => void; - onShowToast: (message: string, options: ToastOptions) => void; + onShowToast: (message: string, options?: ToastOptions) => void; view: EditorView; }; @@ -70,7 +70,7 @@ class LinkEditor extends React.Component { }; get href(): string { - return this.props.mark ? this.props.mark.attrs.href : ""; + return sanitizeHref(this.props.mark?.attrs.href) ?? ""; } get suggestedLinkTitle(): string { @@ -229,7 +229,12 @@ class LinkEditor extends React.Component { handleOpenLink = (event: React.MouseEvent): void => { event.preventDefault(); - this.props.onClickLink(this.href, event); + + try { + this.props.onClickLink(this.href, event); + } catch (err) { + this.props.onShowToast(this.props.dictionary.openLinkError); + } }; handleCreateLink = async (value: string) => {