From ae65f9a70dcae056723f1ce132337a4949a0d8d2 Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 17 Dec 2024 13:37:52 +0100 Subject: [PATCH] fix(link): Don't throw exception on invalid URL href When pasting strings with invalid URLs, `new URL()` in `renderHTML()` of the Link extension threw an error, which made the paste parser choke. We should catch this exception and handle it gracefully to not break HTML parsing completely with invalid URLs. Signed-off-by: Jonas --- src/marks/Link.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/marks/Link.js b/src/marks/Link.js index 11b1a0f102c..96232e0f076 100644 --- a/src/marks/Link.js +++ b/src/marks/Link.js @@ -60,10 +60,15 @@ const Link = TipTapLink.extend({ renderHTML(options) { const { mark } = options - const url = new URL(mark.attrs.href, window.location) - const href = PROTOCOLS_TO_LINK_TO.includes(url.protocol) - ? domHref(mark, this.options.relativePath) - : '#' + let href + try { + const url = new URL(mark.attrs.href, window.location) + href = PROTOCOLS_TO_LINK_TO.includes(url.protocol) + ? domHref(mark, this.options.relativePath) + : '#' + } catch (error) { + href = '#' + } return ['a', { ...mark.attrs, href,