mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-22 06:24:14 -05:00
[Bug Report] Relative links in markdown #8487
Closed
opened 2025-11-02 08:08:13 -06:00 by GiteaMirror
·
41 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.2
v1.16.1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rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
No Label
type/bug
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#8487
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @schorsch13 on GitHub (Feb 4, 2022).
Introduction
When using relative links in markdown files you have to use either
./file.mdorfile.md. When trying to use/file.mdyou will get redirected to the root of the gitea instance.Example
https://try.gitea.io/schorsch/relative-links-in-markdown
Proposal
Change
/file.mdfrom directing to the web root to the project rootCredits
The bug was discovered by the codeberg user ivan-paleo. For further information have a look at the issue at codeberg: https://codeberg.org/Codeberg/Community/issues/252
@zeripath commented on GitHub (Feb 4, 2022):
This was fixed at some point and something has caused a regression!!
@zeripath commented on GitHub (Feb 4, 2022):
Yes this was fixed in #15088
This is particularly irritating as there was even a test created to prevent this from happening YET AGAIN
@zeripath commented on GitHub (Feb 4, 2022):
Let's just go through this again.
The base url for an image link rendered in a file GH is:
/owner/repo/blob/branch/path/to/file/Relative links may traverse out of the repo i.e. if a file that is in
/ofowner/repoon the default branchmasterhas a link:../../../../owner2/repo2then it would like to
/owner2/repo2directly.Links that start with aThis is not true!/e.g./../../../owner2/repo2do not traverse out of the repo.Essentially a leading
/is dropped from the links and then the path is made relative to the branch linkI'll do some more test cases in pathological and properly add tests to gitea to prevent this from happening yet again.
Now in issues and presumably elsewhere the opposite happens:
A
/A
../A
../../A
../../../A
../../../../A
../../../../../A
../../../../../../A
/../A
@zeripath commented on GitHub (Feb 5, 2022):
OK I guess we need the following (this is for a gitea mounted on a suburl /gitea):
One slight problem is that this this is still not github compatible - githubs blob urls are:
https://github.com/zeripath/pathological/blob/master/README.md
Whereas the equivalent in Gitea:
https://try.gitea.io/arandomer/pathological/src/branch/master/README.md
So we're already slightly incompatible.
However, the
/behaviour would be the least we should do.@zeripath commented on GitHub (Feb 5, 2022):
TestCase to add to modules/markup/markdown/markdown_test.go
@charles-997 commented on GitHub (Jun 23, 2022):
Has there been any progress on this bug? This seems like a reasonably important feature-breaking bug!
I was surprised to see that my relative links in existing repositories do not function properly in Gitea.
@xbreaker commented on GitHub (Dec 28, 2022):
Same problem with using HTML A tag in markdown with relative file name
Steps:
<a href="readme.md>readme</a>)/repo/src/branch/file.mdinstead of/repo/src/branch/main/file.mdDemo: https://try.gitea.io/aybe/markdown-branch/
@lunny commented on GitHub (May 9, 2023):
From https://try.gitea.io/aybe/markdown-branch/ , only relative link from a tag is wrong. Maybe it's accepted?
@ell1e commented on GitHub (Sep 25, 2023):
I just ran into this, sadly it seems to break almost all links in my documentation so this is a really high impact bug in my opinion. Especially since with the GitHub mirror it works fine.
Here's a demo file with a link that should work but it doesn't:
https://try.gitea.io/blablablablab/BlaTest/src/branch/main/A%20B/outsidelink.md
(The big bold (test link) is what you want to click. Expected behavior is that it gets you to the target file in the repository root, actual behavior is some nonsensical location.)
@vilunov commented on GitHub (Jan 29, 2024):
In original post it is said that relative links such as
[text](file.md)or[text](./file.md)resolve correctly, but absolute ones do not. This is not my experience with Gitea 1.21.4. Example (this was fixed by downgrading to 1.21.3)I expect that a link such as
[Project structure](crates/readme.md)in the project readme should be resolved toexample.com/org/repo/src/branch/main/crates/readme.md, instead it is resolved toexample.com/org/repo/crates/readme.md, making it pretty much useless, as it is always broken.@vilunov commented on GitHub (Jan 30, 2024):
The issue above seems to be a regression between 1.21.3 and 1.21.4, probably even by #28803
Fortunately, there was no migration in 1.21.4, it was easy to downgrade one patch version
@LamaBleu commented on GitHub (Jan 30, 2024):
Thank you so much @vilunov, you saved my day. Downgrade to 1.21.3 solved this annoying issue.
@vilunov commented on GitHub (Jan 30, 2024):
@KN4CK3R sorry, pinging for visibility since you made the MR and you seem to be responsible for that area.
@KN4CK3R commented on GitHub (Jan 30, 2024):
Can't reproduce it on current main. Was it fixed by #28909?
@vilunov commented on GitHub (Jan 31, 2024):
Thanks, sorry for panicking. Relative links work again, but the absolute ones are still broken.
A link such as
/docs/running.mdwill be rendered as it is in html and will lead tolocalhost:3000/docs/running.mdThis is on gitea/gitea:1.21-nightly docker image
@KN4CK3R commented on GitHub (Jan 31, 2024):
Ok, that's not a regression of my PR 🎉 Gitea always rendered them like that. It's debatable what the root is for absolute links. Even Github is inconsistent with the links.
Inside issue:
A
/A
../A
../../A
../../../A
../../../../A
../../../../../A
../../../../../../A
/../A
Inside repo:
4398ccfc63/README.mdA fix would be to strip the
/prefix for links too:3e8414179c/modules/markup/markdown/goldmark.go (L148)@vilunov commented on GitHub (Jan 31, 2024):
GitHub is not very consistent even when it comes to rendering
README.mdas a repo front page or as an individual file.Example:
link in the first footnote at the end of
README.mdhttps://github.com/ratijas/kdesrc-build-sublime -- renders as
https://github.com/ratijas/plugins/gen_conf_options.pyhttps://github.com/ratijas/kdesrc-build-sublime/blob/master/README.md -- renders as
https://github.com/ratijas/kdesrc-build-sublime/blob/master/plugins/gen_conf_options.pyIt really is tricky
@ell1e commented on GitHub (Mar 24, 2024):
@vilunov the first one seems more like a bug, doesn't it? usually in almost all places on GitHub it behaves like the 2nd example. maybe they just forgot about this corner case of footnotes in the one location, that feels like the most likely reason.
on gitea, sadly it still doesn't seem to work for links starting with
/ever, not even in some cases, see "Broken Example 2" here. this makes writing documentation where individual pages can be moved around inside the documentation folder without all their links to other files breaking quite difficult. so i hope this can be fixed eventually.edit: this also can't be just fixed on the user side by leaving the
/away, since when your documentation page is in various sub folders and links to neighboring pages but in other subfolders, you will need to use tons of..to climb out of where your current doc page is when omitting/(= all outgoing links in the page break when the page is moved around in your repository) while with/it's always relative to the repository base (= a doc page can be moved around without all its outgoing links to others breaking). on github this works perfectly fine, on gitea it doesn't. this use case is also not relevant outside of markdown files inside the repo for documentation, so that e.g. github doesn't also apply this behavior in issue tickets makes sense in my humble opinion.@levicki commented on GitHub (May 1, 2024):
I am having (a variation of?) this problem on the latest version of Gitea (served at root, not at sub-path) — For example I write:
In the Release description field (which works fine on Github and Gitlab) and the link is replaced with:
And results in 404 error when clicked. Actual README.md link in the source tree shows as:
I don't think either would be correct for Releases though — it should link to specific tagged release version of the file.
The only way I can produce a correct link is if I do it manually like this:
Which results in:
It would be nice if Gitea was smart enough to do that sort of expansion for me if I provide a relative path without leading
/or./.@neutronstriker commented on GitHub (Jun 22, 2024):
Is this bug resolved now, I am facing the same issue with version 1.21.4.
-Thanks.
@wxiaoguang commented on GitHub (Jun 22, 2024):
It is not really fixed. Because the "absolute path" link (starting with a slash
/xxxx) handling is quite tricky and ambiguous.And, if we change this behavior, it is a "breaking" change and will make all existing "absolute-path" links broken.
@neutronstriker commented on GitHub (Jun 22, 2024):
Which means we need to use /src/branch/main/ as a prefix right?
@wxiaoguang commented on GitHub (Jun 22, 2024):
Or use relative path like
../../foo/bar.Maybe I could take a try in 1.23 to "fix/improve" the path handling, but I can't promise at the moment.
@busslina commented on GitHub (Jun 22, 2024):
I moved recently to Forgejo, based on Gitea, and works fine.
Even MD header URL links works fine, which I think is not the same with Gitea.
@neutronstriker commented on GitHub (Jun 22, 2024):
I just updated my installation to 1.22.0 and my issue got resolved, my issue was the 1st case referenced in comment https://github.com/go-gitea/gitea/issues/18592#issuecomment-1030591957
@wxiaoguang commented on GitHub (Jun 22, 2024):
There are some different path problems, some have been fixed, while some are still not. Pretty sure they do not have the proper fix either.
Forgejo is still largely based on Gitea's work, but they skipped some Gitea's commits (even some are security related) so I guess it couldn't be more complete than Gitea.
@wxiaoguang commented on GitHub (Jun 22, 2024):
Made some tests on GitHub, I think we could just copy the behavior (and mark it as breaking)
44cc37ef49/test.md6bd6f1da05/dir/test.mdActually, the rule is simple:
But not sure whether we should 100% follow it ........
@levicki commented on GitHub (Jun 22, 2024):
I vote for using the same logic as GitHub — that makes it easier to have both private Gitea and public GitHub repo with correct links in both.
Also please make sure that it works not just in issues and comments but in releases as well. Thanks for looking into it and taking time to fix it.
@ell1e commented on GitHub (Jun 22, 2024):
In Foregjo 7.0.0 this seems not fixed, and linking e.g.
/docs/start.mdinside a repository's main folder inside aREADME.md, won't actually link tohttps://instance.org/user/repo/src/branch/main/docs/start.mdas it probably should. At least as far as I can tell.@wxiaoguang commented on GitHub (Jun 22, 2024):
Although this bug is not fully fixed on either side, actually they missed many bug fixes or improvements, because they hard-forked and skipped many commits.
@delvh commented on GitHub (Jun 22, 2024):
😮💨
guys, I've marked the comments above as off-topic.
They have nothing to do with this issue or Gitea.
AFAIK, Forgejo hardforked some months ago and has diverged since.
as such, the two projects can no longer be seen as equal.
If you encounter issues with Forgejo, please discuss it with them instead of in the Gitea issue tracker.
I'll hide my own comment as well to not disturb others.
@busslina commented on GitHub (Jun 22, 2024):
https://forgejo.org/compare-to-gitea/
https://forgejo.org/compare-to-gitea/#better-security
I can be a bridge between both parts because I have no problem with any of both :) haha
@wxiaoguang commented on GitHub (Jun 22, 2024):
Then you could tell them they have some XSS in some pages, but not in Gitea.
@ApplePie420 commented on GitHub (Nov 20, 2024):
v1.21.4, bare metal installation, server as root of subdomain. I have the same problem, e.g.
In
README.mdI haveAnd it doesn't work. Full path to the file is
src/branch/main/docs/schematics.pdf. This is extremely stupid, not only introduces way more text to typo, but just is not intuitive and transferable to other git UIs. I assume this hasn't been resolved yet.@lunny commented on GitHub (Nov 21, 2024):
Can you upgrade to v1.22.3 to try it again?
@wxiaoguang commented on GitHub (Nov 21, 2024):
It hasn't been improved yet. I am still working on some markdown refactorings. If I complete I would tell here.
@wxiaoguang commented on GitHub (Nov 22, 2024):
Refactor markup render system #32612
Almost done, this PR will fix most problems.
@wxiaoguang commented on GitHub (Nov 23, 2024):
Hi ApplePie420 , I have tested your markdown in 1.22, it seems that 1.22 could render that relative path correctly (something should have been fixed there). Would you like to upgrade to 1.22 and take a try? No need to wait for 1.23.
Screenshot:
If anything doesn't work as expected, please provide some reproducible examples. Thank you.
@ell1e commented on GitHub (Nov 23, 2024):
https://demo.gitea.com/ell1e/linktest/src/branch/main/README.md This example suggests relative links with no trailing slash work, but relative links with trailing slash to link to files relative to the root of the file tree still don't work (which they do on GitHub). I hope this is helpful.
@wxiaoguang commented on GitHub (Nov 23, 2024):
Thank you, that's another problem and will be fixed in 1.23 (see my PR #32612)
I think it works as expected now, feel free to try that PR 🙏
@wxiaoguang commented on GitHub (Nov 24, 2024):
#32612 has been merged and the nightly builds are ready (docker: main-nightly, binary: https://dl.gitea.com/gitea/main-nightly/ ), feel free to try it.
I think the "relative/absolute" path problem should have been fixed for most cases.
I have done my best to avoid regressions, if there is anything wrong, please let me know and I will fix bugs in first time.
Update: found a regression Fix markup render regression and fix some tests #32640