From 2acf260f85b02fee8faf2eafdd984c7cc47a0653 Mon Sep 17 00:00:00 2001 From: Alex Casillas Date: Fri, 29 Nov 2024 12:38:36 +0100 Subject: [PATCH] fix(link): object replacement character sanitization #5679 (#5887) --------- Co-authored-by: Alex Casillas --- .changeset/unlucky-ravens-build.md | 5 +++++ packages/extension-link/src/link.ts | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/unlucky-ravens-build.md diff --git a/.changeset/unlucky-ravens-build.md b/.changeset/unlucky-ravens-build.md new file mode 100644 index 000000000..49d1ec100 --- /dev/null +++ b/.changeset/unlucky-ravens-build.md @@ -0,0 +1,5 @@ +--- +"@tiptap/extension-link": patch +--- + +fix: #5679 - perform string sanitization to remove unwanted "object replacement characters" from the before performing link detection diff --git a/packages/extension-link/src/link.ts b/packages/extension-link/src/link.ts index b9b882995..bb8ead872 100644 --- a/packages/extension-link/src/link.ts +++ b/packages/extension-link/src/link.ts @@ -351,7 +351,12 @@ export const Link = Mark.create({ if (text) { const { protocols, defaultProtocol } = this.options - const links = find(text).filter( + // Prosemirror replaces zero-width non-joiner characters + // with Object Replacement Character from unicode. + // Therefore, linkifyjs does not recognize the + // link properly. We replace these characters + // with regular spaces to fix this issue. + const links = find(text.replaceAll('\uFFFC', ' ')).filter( item => item.isLink && this.options.isAllowedUri(item.value, { defaultValidate: href => !!isAllowedUri(href, protocols),