Skip to content

Commit 1322cd7

Browse files
GiteaBotyp05327wolfogrejolheisersilverwind
authored
Use correct README link to render the README (#23152) (#23264)
Backport #23152 `renderReadmeFile` needs `readmeTreelink` as parameter but gets `treeLink`. The values of them look like as following: `treeLink`: `/{OwnerName}/{RepoName}/src/branch/{BranchName}` `readmeTreelink`: `/{OwnerName}/{RepoName}/src/branch/{BranchName}/{ReadmeFileName}` `path.Dir` in https://github.com/go-gitea/gitea/blob/8540fc45b11eff9a73753ca139f8ea5c38509bf5/routers/web/repo/view.go#L316 should convert `readmeTreelink` into `/{OwnerName}/{RepoName}/src/branch/{BranchName}` instead of the current `/{OwnerName}/{RepoName}/src/branch`. Fixes #23151 Co-authored-by: yp05327 <[email protected]> Co-authored-by: Jason Song <[email protected]> Co-authored-by: John Olheiser <[email protected]> Co-authored-by: silverwind <[email protected]>
1 parent 464bbd7 commit 1322cd7

File tree

7 files changed

+23
-2
lines changed

7 files changed

+23
-2
lines changed

models/fixtures/repository.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
fork_id: 0
2626
is_template: false
2727
template_id: 0
28-
size: 6708
28+
size: 7028
2929
is_fsck_enabled: true
3030
close_issues_via_commit_in_any_branch: false
3131

routers/web/repo/view.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
186186
return
187187
}
188188

189-
renderReadmeFile(ctx, readmeFile, treeLink)
189+
renderReadmeFile(ctx, readmeFile, fmt.Sprintf("%s/%s", treeLink, readmeFile.name))
190190
}
191191

192192
// localizedExtensions prepends the provided language code with and without a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
78fb907e3a3309eae4fe8fef030874cebbf1cd5e

tests/integration/repo_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,23 @@ func TestViewRepoDirectory(t *testing.T) {
256256
assert.Zero(t, repoTopics.Length())
257257
assert.Zero(t, repoSummary.Length())
258258
}
259+
260+
func TestMarkDownImage(t *testing.T) {
261+
defer tests.PrepareTestEnv(t)()
262+
263+
session := loginUser(t, "user2")
264+
265+
req := NewRequest(t, "GET", "/user2/repo1/src/branch/home-md-img-check")
266+
resp := session.MakeRequest(t, req, http.StatusOK)
267+
268+
htmlDoc := NewHTMLParser(t, resp.Body)
269+
_, exists := htmlDoc.doc.Find(`img[src="/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg"]`).Attr("src")
270+
assert.True(t, exists, "Repo home page markdown image link check failed")
271+
272+
req = NewRequest(t, "GET", "/user2/repo1/src/branch/home-md-img-check/README.md")
273+
resp = session.MakeRequest(t, req, http.StatusOK)
274+
275+
htmlDoc = NewHTMLParser(t, resp.Body)
276+
_, exists = htmlDoc.doc.Find(`img[src="/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg"]`).Attr("src")
277+
assert.True(t, exists, "Repo src page markdown image link check failed")
278+
}

0 commit comments

Comments
 (0)