Skip to content

fix(links): keep purely numeric link targets as strings - #9546

Merged
mejo- merged 2 commits into
nextcloud:mainfrom
upskaling:fix/9519-numeric-link-href
Nov 5, 2026
Merged

mejo- merged 2 commits into
nextcloud:mainfrom
upskaling:fix/9519-numeric-link-href

Conversation

@upskaling

Copy link
Copy Markdown
Contributor

📝 Summary

Opening a Markdown document containing a link with a purely numeric target
([test](12345678901234) or [[12345678901234|test]]) crashed the editor
with TypeError: href?.startsWith is not a function.

The link mark's href attribute was defined without a parseHTML
function, so Tiptap fell back to its default attribute parsing, which casts
numeric-looking strings to numbers. The link pill plugin then passed that
value to isLinkToSelfWithHash(), where startsWith() failed.

This defines parseHTML for href using the existing parseHref() helper,
so the attribute always stays a string. It also restores the existing
rewrite of old file-picker links to /f/<fileId>, which was bypassed by the
same default parsing.

I encountered this while using the Foam
extension for VS Code. Foam generates wiki links with numeric labels and can
emit reference definitions such as:

[12345678901234]: ../12345678901234.md "test"

Closer compatibility with Foam's wiki-link format would be valuable, but it
is out of scope for this PR. This change only makes documents containing
purely numeric link targets openable again.

Regression tests cover both plain Markdown links and wiki links through the
Markdown round-trip, plus the link pill plugin. The fix was also verified
manually in a Nextcloud development instance.

🖼️ Screenshots

🏚️ Before 🏡 After
Editor stays empty and fails to load (see #9519) 9519-before 9519-after

🚧 TODO

None.

🏁 Checklist

  • Code is properly formatted (npm run lint / npm run stylelint / composer run cs:check)
  • Sign-off message is added to all commits
  • Tests (unit, integration and/or end-to-end) passing and the changes are covered with tests
  • Documentation (README or documentation) has been updated or is not required

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI tools
  • The AI-generated content was reviewed, comprehended and tested by a human

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/<fileId>`.

Assisted-by: OpenCode:DeepSeek V4.1 Flash
Signed-off-by: upskaling <upskaling@users.noreply.github.com>
@mejo-
mejo- merged commit d588d74 into nextcloud:main Nov 5, 2026
62 of 65 checks passed
@mejo-

mejo- commented Nov 5, 2026

Copy link
Copy Markdown
Member

/backport to stable35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text editor fails to open documents containing a link with a purely numeric href (href?.startsWith is not a function)

3 participants