Skip to content

Commit 976db2a

Browse files
authored
Do not show issue context popup on external issues (#17050)
The issues pop-up context cannot work for external issues - therefore do not show these. Fix #17047 Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent fc97e06 commit 976db2a

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

modules/markup/html.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ func issueIndexPatternProcessor(ctx *RenderContext, node *html.Node) {
830830
reftext := node.Data[ref.RefLocation.Start:ref.RefLocation.End]
831831
if exttrack && !ref.IsPull {
832832
ctx.Metas["index"] = ref.Issue
833-
link = createLink(com.Expand(ctx.Metas["format"], ctx.Metas), reftext, "ref-issue")
833+
link = createLink(com.Expand(ctx.Metas["format"], ctx.Metas), reftext, "ref-issue ref-external-issue")
834834
} else {
835835
// Path determines the type of link that will be rendered. It's unknown at this point whether
836836
// the linked item is actually a PR or an issue. Luckily it's of no real consequence because

modules/markup/html_internal_test.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
9696
// numeric: render inputs with valid mentions
9797
test := func(s, expectedFmt, marker string, indices ...int) {
9898
var path, prefix string
99+
isExternal := false
99100
if marker == "!" {
100101
path = "pulls"
101102
prefix = "http://localhost:3000/someUser/someRepo/pulls/"
102103
} else {
103104
path = "issues"
104105
prefix = "https://someurl.com/someUser/someRepo/"
106+
isExternal = true
105107
}
106108

107109
links := make([]interface{}, len(indices))
@@ -111,8 +113,13 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
111113
expectedNil := fmt.Sprintf(expectedFmt, links...)
112114
testRenderIssueIndexPattern(t, s, expectedNil, &RenderContext{Metas: localMetas})
113115

116+
class := "ref-issue"
117+
if isExternal {
118+
class += " ref-external-issue"
119+
}
120+
114121
for i, index := range indices {
115-
links[i] = numericIssueLink(prefix, "ref-issue", index, marker)
122+
links[i] = numericIssueLink(prefix, class, index, marker)
116123
}
117124
expectedNum := fmt.Sprintf(expectedFmt, links...)
118125
testRenderIssueIndexPattern(t, s, expectedNum, &RenderContext{Metas: numericMetas})
@@ -178,7 +185,7 @@ func TestRender_IssueIndexPattern4(t *testing.T) {
178185
test := func(s, expectedFmt string, names ...string) {
179186
links := make([]interface{}, len(names))
180187
for i, name := range names {
181-
links[i] = alphanumIssueLink("https://someurl.com/someUser/someRepo/", "ref-issue", name)
188+
links[i] = alphanumIssueLink("https://someurl.com/someUser/someRepo/", "ref-issue ref-external-issue", name)
182189
}
183190
expected := fmt.Sprintf(expectedFmt, links...)
184191
testRenderIssueIndexPattern(t, s, expected, &RenderContext{Metas: alphanumericMetas})

modules/markup/sanitizer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func createDefaultPolicy() *bluemonday.Policy {
6666
}
6767

6868
// Allow classes for anchors
69-
policy.AllowAttrs("class").Matching(regexp.MustCompile(`ref-issue`)).OnElements("a")
69+
policy.AllowAttrs("class").Matching(regexp.MustCompile(`ref-issue( ref-external-issue)?`)).OnElements("a")
7070

7171
// Allow classes for task lists
7272
policy.AllowAttrs("class").Matching(regexp.MustCompile(`task-list-item`)).OnElements("li")

web_src/js/features/contextpopup.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export default function initContextPopups() {
77
if (!refIssues.length) return;
88

99
refIssues.each(function () {
10+
if ($(this).hasClass('ref-external-issue')) {
11+
return;
12+
}
1013
const [index, _issues, repo, owner] = $(this).attr('href').replace(/[#?].*$/, '').split('/').reverse();
1114

1215
const el = document.createElement('div');

0 commit comments

Comments
 (0)