From d182756013864e7e47b40af1a2813a557dfa1747 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 029fb510446..1878f43958b 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,