From f882e38c91f815df26bb91e95a97f32b39fe5bfc Mon Sep 17 00:00:00 2001 From: upskaling Date: Wed, 4 Nov 2026 18:40:14 +0100 Subject: [PATCH] fix(links): keep purely numeric link targets as strings Defining the `href` attribute without a `parseHTML` function makes Tiptap's default attribute parsing cast numeric-looking strings to numbers. `isLinkToSelfWithHash` then calls `startsWith` on a number and the editor fails to open documents with links like `[test](12345678901234)` or `[[12345678901234|test]]`. Parse the href with `parseHref` so it always stays a string. This also restores the rewrite of old file-picker links to `/f/`. Assisted-by: OpenCode:DeepSeek V4.1 Flash Signed-off-by: upskaling --- src/marks/Link.ts | 1 + src/tests/markdown.spec.js | 3 +++ src/tests/plugins/linkPill.spec.ts | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/src/marks/Link.ts b/src/marks/Link.ts index 82402fc67cd..e650e65b7d4 100644 --- a/src/marks/Link.ts +++ b/src/marks/Link.ts @@ -99,6 +99,7 @@ const Link = TipTapLink.extend({ return { href: { default: null, + parseHTML: (element: HTMLElement) => parseHref(element), }, title: { default: null, diff --git a/src/tests/markdown.spec.js b/src/tests/markdown.spec.js index 924a9611146..245c8f4ed70 100644 --- a/src/tests/markdown.spec.js +++ b/src/tests/markdown.spec.js @@ -99,9 +99,12 @@ describe('Markdown though editor', () => { // Issue #4900 expect(markdownThroughEditor('[`code`](foo)')).toBe('[`code`](foo)') expect(markdownThroughEditor('[text with `code` inside](foo)')).toBe('[text with `code` inside](foo)') + // Purely numeric targets must stay strings (issue #9519) + expect(markdownThroughEditor('[test](12345678901234)')).toBe('[test](12345678901234)') // Wiki-style links (issue #4795) expect(markdownThroughEditor('[[WikiLink]]')).toBe('[[WikiLink]]') expect(markdownThroughEditor('text [[wikiLink]] more')).toBe('text [[wikiLink]] more') + expect(markdownThroughEditor('[[12345678901234|test]]')).toBe('[[12345678901234|test]]') // Reference-style links (issue #5820) const referenceShortcutTest = 'Test with [Case-Sensitive Reference] in it.\n\n[Case-Sensitive Reference]: https://example.org/\n' diff --git a/src/tests/plugins/linkPill.spec.ts b/src/tests/plugins/linkPill.spec.ts index fa2473d0fc0..28c675f3f6d 100644 --- a/src/tests/plugins/linkPill.spec.ts +++ b/src/tests/plugins/linkPill.spec.ts @@ -24,6 +24,14 @@ describe('linkPill plugin', () => { editor.destroy() }) + it('handles purely numeric hrefs', () => { + const editor = createCustomEditor('

Test

', [Link]) + const spans = findLinkSpans(editor.state.doc) + expect(spans).toHaveLength(1) + expect(spans[0].mark.attrs.href).toBe('12345678901234') + editor.destroy() + }) + it('skips anchor links', () => { const editor = createCustomEditor('

Test

', [Link]) expect(findLinkSpans(editor.state.doc)).toHaveLength(0)