Skip to content

Fix relative repository file link with percent sign

What does this MR do and why?

In Markdown, you can add a relative link to a file in a repository (see docs):

This line shows a [link to a repository file in the same directory](permissions.md)

Normally it works as desired and the relative link is converted to an absolute link. (In #382171 (closed), we fixed it to also make the link in notification emails absolute.)

But there's another ~bug: If the file in the repository contains a percent sign (%), the link processing does not work as desired. Let's fix this bug.

Example:

Notification email
Comment in MR or issue [test%.txt](test%.txt)
Resulting HTML: before MR <a href="test%.txt" ... >test%.txt</a>
still a relative link that doesn't work in email
Resulting HTML: after MR <a href="http://localhost:3000/gitlab-org/gitlab-shell/-/blob/main/test%25.txt" ... >test%.txt</a>
correct link (200 OK)
Web UI
Comment in MR [test%.txt](test%.txt)
Resulting HTML: before MR <a href="test%.txt" ... >test%.txt</a>
links to http://localhost:3000/gitlab-org/gitlab-shell/-/merge_requests/test%.txt (400 Bad Request)
Resulting HTML: after MR <a href="/gitlab-org/gitlab-shell/-/blob/main/test%25.txt" ... >test%.txt</a>
links to http://localhost:3000/gitlab-org/gitlab-shell/-/blob/main/test%25.txt (200 OK)
Comment in issue [test%.txt](test%.txt)
Resulting HTML: before MR <a href="test%.txt" ... >test%.txt</a>
links to http://localhost:3000/gitlab-org/gitlab-shell/-/issues/test%.txt (400 Bad Request)
Resulting HTML: after MR <a href="/gitlab-org/gitlab-shell/-/blob/main/test%25.txt" ... >test%.txt</a>
links to http://localhost:3000/gitlab-org/gitlab-shell/-/blob/main/test%25.txt (200 OK)

🛠 with at Siemens

/cc @bufferoverflow

How to set up and validate locally

  1. Navigate to a project (http://localhost:3000/gitlab-org/gitlab-shell) and add a file containing % in its name to the main branch (e.g. test%.txt).
  2. Navigate to/create an issue or a MR in the project: http://localhost:3000/gitlab-org/gitlab-shell/-/issues/11
  3. Add a comment: test%.txt
  4. Check the resulting link/HTML of the comment
  5. Check the resulting notification email

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Jonas Wälter

Merge request reports