[GITEA] Make reference URL absolute

- Make the reference URL in the "Reference in New issue" feature
absolute again as it wouldn't render as a link otherwise.
- Adds integration test.
- Regression by 769be877f2
- Resolves #2012
This commit is contained in:
Gusted 2024-01-05 20:00:13 +01:00
parent 5f7875e416
commit c74bae2897
No known key found for this signature in database
GPG key ID: FD821B732837125F
2 changed files with 30 additions and 2 deletions

View file

@ -5,9 +5,9 @@
<div class="menu">
{{$referenceUrl := ""}}
{{if .issue}}
{{$referenceUrl = printf "%s#%s" .ctxData.Issue.Link .item.HashTag}}
{{$referenceUrl = printf "%s#%s" .ctxData.Issue.HTMLURL .item.HashTag}}
{{else}}
{{$referenceUrl = printf "%s/files#%s" .ctxData.Issue.Link .item.HashTag}}
{{$referenceUrl = printf "%s/files#%s" .ctxData.Issue.HTMLURL .item.HashTag}}
{{end}}
<div class="item context js-aria-clickable" data-clipboard-text-type="url" data-clipboard-text="{{$referenceUrl}}">{{ctx.Locale.Tr "repo.issues.context.copy_link"}}</div>
{{if and .ctxData.IsSigned (not .ctxData.Repository.IsArchived)}}

View file

@ -699,3 +699,31 @@ func TestIssuePinMove(t *testing.T) {
issue = unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: issue.ID})
assert.EqualValues(t, newPosition, issue.PinOrder)
}
func TestAbsoluteReferenceURL(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user2")
issue1 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue1.RepoID})
req := NewRequest(t, "GET", fmt.Sprintf("%s/issues/%d", repo.FullName(), issue1.Index))
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
t.Run("Issue", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
referenceURL, ok := htmlDoc.Find(".reference-issue").Attr("data-reference")
assert.True(t, ok)
assert.EqualValues(t, setting.AppURL+"user2/repo1/issues/1#issue-1", referenceURL)
})
t.Run("Comment", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
referenceURL, ok := htmlDoc.Find(`[id^="issuecomment"] .reference-issue`).Attr("data-reference")
assert.True(t, ok)
assert.EqualValues(t, setting.AppURL+"user2/repo1/issues/1#issuecomment-2", referenceURL)
})
}