Skip to content

Commit 6b7e145

Browse files
committed
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 <jonas@freesources.org>
1 parent 1353d69 commit 6b7e145

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/marks/Link.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,15 @@ const Link = TipTapLink.extend({
6060

6161
renderHTML(options) {
6262
const { mark } = options
63-
const url = new URL(mark.attrs.href, window.location)
64-
const href = PROTOCOLS_TO_LINK_TO.includes(url.protocol)
65-
? domHref(mark, this.options.relativePath)
66-
: '#'
63+
let href
64+
try {
65+
const url = new URL(mark.attrs.href, window.location)
66+
href = PROTOCOLS_TO_LINK_TO.includes(url.protocol)
67+
? domHref(mark, this.options.relativePath)
68+
: '#'
69+
} catch (error) {
70+
href = mark.attrs.href
71+
}
6772
return ['a', {
6873
...mark.attrs,
6974
href,

0 commit comments

Comments
 (0)