Skip to content

Commit

Permalink
fix: Correctly sanitize href in link editor 'open url' flow
Browse files Browse the repository at this point in the history
  • Loading branch information
tommoor committed Jul 21, 2022
1 parent 4b4b0f7 commit ef2abf8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/editor/components/LinkEditor.tsx
Expand Up @@ -44,7 +44,7 @@ type Props = {
href: string,
event: React.MouseEvent<HTMLButtonElement>
) => void;
onShowToast: (message: string, options: ToastOptions) => void;
onShowToast: (message: string, options?: ToastOptions) => void;
view: EditorView;
};

Expand All @@ -70,7 +70,7 @@ class LinkEditor extends React.Component<Props, State> {
};

get href(): string {
return this.props.mark ? this.props.mark.attrs.href : "";
return sanitizeHref(this.props.mark?.attrs.href) ?? "";
}

get suggestedLinkTitle(): string {
Expand Down Expand Up @@ -229,7 +229,12 @@ class LinkEditor extends React.Component<Props, State> {

handleOpenLink = (event: React.MouseEvent<HTMLButtonElement>): 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) => {
Expand Down

0 comments on commit ef2abf8

Please sign in to comment.