Fix relative repository file link with percent sign
requested to merge siemens/gitlab:markdown-rendering/relative-repository-file-link-percent into master
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> |
Resulting HTML: after MR |
<a href="http://localhost:3000/gitlab-org/gitlab-shell/-/blob/main/test%25.txt" ... >test%.txt</a> |
Web UI | |
---|---|
Comment in MR | [test%.txt](test%.txt) |
Resulting HTML: before MR |
<a href="test%.txt" ... >test%.txt</a> 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> 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> 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> http://localhost:3000/gitlab-org/gitlab-shell/-/blob/main/test%25.txt (200 OK) |
/cc @bufferoverflow
How to set up and validate locally
- 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
). - Navigate to/create an issue or a MR in the project: http://localhost:3000/gitlab-org/gitlab-shell/-/issues/11
- Add a comment: test%.txt
- Check the resulting link/HTML of the comment
- 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.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Jonas Wälter