Skip to content

Commit ca1a295

Browse files
committed
fix test
1 parent ebd88a5 commit ca1a295

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

modules/markup/html.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ package markup
55

66
import (
77
"bytes"
8-
"fmt"
9-
"html/template"
108
"io"
119
"regexp"
10+
"slices"
1211
"strings"
1312
"sync"
1413

1514
"code.gitea.io/gitea/modules/markup/common"
16-
"code.gitea.io/gitea/modules/setting"
17-
1815
"golang.org/x/net/html"
1916
"golang.org/x/net/html/atom"
2017
"mvdan.cc/xurls/v2"
@@ -85,12 +82,10 @@ var globalVars = sync.OnceValue[*globalVarsType](func() *globalVarsType {
8582
v.emojiShortCodeRegex = regexp.MustCompile(`:[-+\w]+:`)
8683

8784
// example: https://domain/org/repo/pulls/27#hash
88-
v.issueFullPattern = regexp.MustCompile(regexp.QuoteMeta(setting.AppURL) +
89-
`[\w_.-]+/[\w_.-]+/(?:issues|pulls)/((?:\w{1,10}-)?[1-9][0-9]*)([\?|#](\S+)?)?\b`)
85+
v.issueFullPattern = regexp.MustCompile(`https?://(?:\S+/)[\w_.-]+/[\w_.-]+/(?:issues|pulls)/((?:\w{1,10}-)?[1-9][0-9]*)([\?|#](\S+)?)?\b`)
9086

9187
// example: https://domain/org/repo/pulls/27/files#hash
92-
v.filesChangedFullPattern = regexp.MustCompile(regexp.QuoteMeta(setting.AppURL) +
93-
`[\w_.-]+/[\w_.-]+/pulls/((?:\w{1,10}-)?[1-9][0-9]*)/files([\?|#](\S+)?)?\b`)
88+
v.filesChangedFullPattern = regexp.MustCompile(`https?://(?:\S+/)[\w_.-]+/[\w_.-]+/pulls/((?:\w{1,10}-)?[1-9][0-9]*)/files([\?|#](\S+)?)?\b`)
9489

9590
v.tagCleaner = regexp.MustCompile(`<((?:/?\w+/\w+)|(?:/[\w ]+/)|(/?[hH][tT][mM][lL]\b)|(/?[hH][eE][aA][dD]\b))`)
9691
v.nulCleaner = strings.NewReplacer("\000", "")
@@ -227,15 +222,16 @@ func RenderCommitMessageSubject(
227222
ctx *RenderContext,
228223
defaultLink, content string,
229224
) (string, error) {
230-
procs := commitMessageSubjectProcessors
231-
rendered, err := renderProcessString(ctx, procs, content)
232-
if err != nil {
233-
return "", err
234-
}
235-
if defaultLink != "" {
236-
rendered = fmt.Sprintf(`<a href="%s" class="muted">%s</a>`, template.HTMLEscapeString(defaultLink), rendered)
237-
}
238-
return rendered, nil
225+
procs := slices.Clone(commitMessageSubjectProcessors)
226+
procs = append(procs, func(ctx *RenderContext, node *html.Node) {
227+
ch := &html.Node{Parent: node, Type: html.TextNode, Data: node.Data}
228+
node.Type = html.ElementNode
229+
node.Data = "a"
230+
node.DataAtom = atom.A
231+
node.Attr = []html.Attribute{{Key: "href", Val: defaultLink}, {Key: "class", Val: "muted"}}
232+
node.FirstChild, node.LastChild = ch, ch
233+
})
234+
return renderProcessString(ctx, procs, content)
239235
}
240236

241237
// RenderIssueTitle to process title on individual issue/pull page

modules/markup/html_issue.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"code.gitea.io/gitea/modules/base"
10+
"code.gitea.io/gitea/modules/httplib"
1011
"code.gitea.io/gitea/modules/log"
1112
"code.gitea.io/gitea/modules/references"
1213
"code.gitea.io/gitea/modules/regexplru"
@@ -35,6 +36,9 @@ func fullIssuePatternProcessor(ctx *RenderContext, node *html.Node) {
3536
}
3637

3738
link := node.Data[m[0]:m[1]]
39+
if !httplib.IsCurrentGiteaSiteURL(ctx.Ctx, link) {
40+
return
41+
}
3842
text := "#" + node.Data[m[2]:m[3]]
3943
// if m[4] and m[5] is not -1, then link is to a comment
4044
// indicate that in the text by appending (comment)

0 commit comments

Comments
 (0)