NcRichText: links to other pages of the instance become app routes

Open Beginner friendly
#9,280 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript
Domain
frontend

Research direction

Start by reading src/components/NcRichText/autolink.ts around lines 148–159, especially how getRoute() removes the router base and resolves the remaining path. Check the reported cases for instance paths outside /apps/forms and paths under that base; done means only links within the app become app routes, while the other examples return null. The issue reports a reproduction through getRoute() but names no test file.

Written by the indexing model from the issue text.

Description

Describe the bug

In an app with a router, NcRichText turns links to pages of the same Nextcloud instance outside the app into app routes, whenever the path happens to match one of the app's routes. A link to the instance root or to a path with one segment, such as https://cloud.example.com/login, is rendered as a RouterLink to /apps/<app>/login in the same tab.

To reproduce
  1. An app whose router has base /apps/forms and a route /:hash (Nextcloud Forms has this).
  2. Render <NcRichText text="[Log in](https://cloud.example.com/login)" use-markdown /> inside that app.
  3. getRoute() returns /login, so the link opens /apps/forms/login instead of /login.

Results of getRoute() with such a router:

URL getRoute() Expected
https://cloud.example.com/ / null
https://cloud.example.com/login /login null
/settings /settings null
https://cloud.example.com/apps/forms/abc /abc /abc
Cause

getRoute() strips the router base from the URL with removePrefixes(), which leaves the URL unchanged when it does not start with the base, and then resolves the unchanged path against the router:

https://github.com/nextcloud-libraries/nextcloud-vue/blob/2c19db3f44bb5e909919f3e81e639e01c8085a87/src/components/NcRichText/autolink.ts#L148-L159

A possible fix is to return null when relativeUrl does not start with relativeRouterBase.

Versions

@nextcloud/vue 9.14.1; the same code is on main (9.15.0).

Context

Found while replacing markdown-it with NcRichText in Nextcloud Forms (nextcloud/forms#3587). Reproduced by calling getRoute() from the 9.14.1 build with a vue-router instance configured like the Forms router; not checked in a browser.

Assisted by ClaudeCode:claude-opus-5-5

Dominant language
Vue
Stars
246
Forks
104
Avg merge
1d 3h
Merged PRs (30d)
79

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nextcloud-libraries/nextcloud-vue

All issues in nextcloud-libraries/nextcloud-vue

Similar issues

More Web Dev issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.