mirror of
https://gitcode.com/gitea/gitea.git
synced 2025-05-28 13:20:20 +08:00
Refactor markup render to fix various path problems (#34114)
* Fix #33972 * Use consistent path resolving for links and medias. * No need to make the markup renders to resolve the paths, instead, the paths are all correctly resolved in the "post process" step. * Fix #33274 * Since 1.23, all paths starting with "/" are relative to current render context (for example: the current repo branch) * Introduce `/:root/path-relative-to-root`, then the path will be rendered as relative to "ROOT_URL"
This commit is contained in:
@ -107,7 +107,7 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
|
||||
isExternal := false
|
||||
if marker == "!" {
|
||||
path = "pulls"
|
||||
prefix = "http://localhost:3000/someUser/someRepo/pulls/"
|
||||
prefix = "/someUser/someRepo/pulls/"
|
||||
} else {
|
||||
path = "issues"
|
||||
prefix = "https://someurl.com/someUser/someRepo/"
|
||||
@ -116,7 +116,7 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
|
||||
|
||||
links := make([]any, len(indices))
|
||||
for i, index := range indices {
|
||||
links[i] = numericIssueLink(util.URLJoin(TestRepoURL, path), "ref-issue", index, marker)
|
||||
links[i] = numericIssueLink(util.URLJoin("/test-owner/test-repo", path), "ref-issue", index, marker)
|
||||
}
|
||||
expectedNil := fmt.Sprintf(expectedFmt, links...)
|
||||
testRenderIssueIndexPattern(t, s, expectedNil, NewTestRenderContext(TestAppURL, localMetas))
|
||||
@ -293,13 +293,13 @@ func TestRender_AutoLink(t *testing.T) {
|
||||
|
||||
// render valid commit URLs
|
||||
tmp := util.URLJoin(TestRepoURL, "commit", "d8a994ef243349f321568f9e36d5c3f444b99cae")
|
||||
test(tmp, "<a href=\""+tmp+"\" class=\"commit\"><code class=\"nohighlight\">d8a994ef24</code></a>")
|
||||
test(tmp, "<a href=\""+tmp+"\" class=\"commit\"><code>d8a994ef24</code></a>")
|
||||
tmp += "#diff-2"
|
||||
test(tmp, "<a href=\""+tmp+"\" class=\"commit\"><code class=\"nohighlight\">d8a994ef24 (diff-2)</code></a>")
|
||||
test(tmp, "<a href=\""+tmp+"\" class=\"commit\"><code>d8a994ef24 (diff-2)</code></a>")
|
||||
|
||||
// render other commit URLs
|
||||
tmp = "https://external-link.gitea.io/go-gitea/gitea/commit/d8a994ef243349f321568f9e36d5c3f444b99cae#diff-2"
|
||||
test(tmp, "<a href=\""+tmp+"\" class=\"commit\"><code class=\"nohighlight\">d8a994ef24 (diff-2)</code></a>")
|
||||
test(tmp, "<a href=\""+tmp+"\" class=\"commit\"><code>d8a994ef24 (diff-2)</code></a>")
|
||||
}
|
||||
|
||||
func TestRender_FullIssueURLs(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user