From a4cb222ec860de827c9170c686686e3b6e454b4d Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 6 Jan 2024 12:07:41 +0800 Subject: [PATCH] fix --- tests/integration/issue_test.go | 19 +++++++++++++++++++ web_src/js/features/repo-issue.js | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index b1080c998a361..4b3f581c2b22f 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -607,3 +607,22 @@ func TestUpdateIssueDeadline(t *testing.T) { assert.EqualValues(t, "2022-04-06", apiIssue.Deadline.Format("2006-01-02")) } + +func TestIssueReferenceURL(t *testing.T) { + defer tests.PrepareTestEnv(t)() + session := loginUser(t, "user2") + + issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) + + req := NewRequest(t, "GET", fmt.Sprintf("%s/issues/%d", repo.FullName(), issue.Index)) + resp := session.MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + // the "reference" uses relative URLs, then JS code will convert them to absolute URLs for current origin, in case users are using multiple domains + ref, _ := htmlDoc.Find(`.timeline-item.comment.first .reference-issue`).Attr("data-reference") + assert.EqualValues(t, "/user2/repo1/issues/1#issue-1", ref) + + ref, _ = htmlDoc.Find(`.timeline-item.comment:not(.first) .reference-issue`).Attr("data-reference") + assert.EqualValues(t, "/user2/repo1/issues/1#issuecomment-2", ref) +} diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index d995b56a5556d..6908e0c912342 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -4,6 +4,7 @@ import {showTemporaryTooltip, createTippy} from '../modules/tippy.js'; import {hideElem, showElem, toggleElem} from '../utils/dom.js'; import {setFileFolding} from './file-fold.js'; import {getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js'; +import {toAbsoluteUrl} from '../utils.js'; const {appSubUrl, csrfToken} = window.config; @@ -526,7 +527,7 @@ export function initRepoIssueReferenceIssue() { const $this = $(this); const content = $(`#${$this.data('target')}`).text(); const poster = $this.data('poster-username'); - const reference = $this.data('reference'); + const reference = toAbsoluteUrl($this.data('reference')); const $modal = $($this.data('modal')); $modal.find('textarea[name="content"]').val(`${content}\n\n_Originally posted by @${poster} in ${reference}_`); $modal.modal('show');