Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Nov 16, 2024
1 parent ebd88a5 commit 78e1eb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
29 changes: 13 additions & 16 deletions modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ package markup

import (
"bytes"
"fmt"
"html/template"
"io"
"regexp"
"slices"
"strings"
"sync"

"code.gitea.io/gitea/modules/markup/common"
"code.gitea.io/gitea/modules/setting"

"golang.org/x/net/html"
"golang.org/x/net/html/atom"
Expand Down Expand Up @@ -85,12 +83,10 @@ var globalVars = sync.OnceValue[*globalVarsType](func() *globalVarsType {
v.emojiShortCodeRegex = regexp.MustCompile(`:[-+\w]+:`)

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

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

v.tagCleaner = regexp.MustCompile(`<((?:/?\w+/\w+)|(?:/[\w ]+/)|(/?[hH][tT][mM][lL]\b)|(/?[hH][eE][aA][dD]\b))`)
v.nulCleaner = strings.NewReplacer("\000", "")
Expand Down Expand Up @@ -227,15 +223,16 @@ func RenderCommitMessageSubject(
ctx *RenderContext,
defaultLink, content string,
) (string, error) {
procs := commitMessageSubjectProcessors
rendered, err := renderProcessString(ctx, procs, content)
if err != nil {
return "", err
}
if defaultLink != "" {
rendered = fmt.Sprintf(`<a href="%s" class="muted">%s</a>`, template.HTMLEscapeString(defaultLink), rendered)
}
return rendered, nil
procs := slices.Clone(commitMessageSubjectProcessors)
procs = append(procs, func(ctx *RenderContext, node *html.Node) {
ch := &html.Node{Parent: node, Type: html.TextNode, Data: node.Data}
node.Type = html.ElementNode
node.Data = "a"
node.DataAtom = atom.A
node.Attr = []html.Attribute{{Key: "href", Val: defaultLink}, {Key: "class", Val: "muted"}}
node.FirstChild, node.LastChild = ch, ch
})
return renderProcessString(ctx, procs, content)
}

// RenderIssueTitle to process title on individual issue/pull page
Expand Down
4 changes: 4 additions & 0 deletions modules/markup/html_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/references"
"code.gitea.io/gitea/modules/regexplru"
Expand Down Expand Up @@ -35,6 +36,9 @@ func fullIssuePatternProcessor(ctx *RenderContext, node *html.Node) {
}

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

0 comments on commit 78e1eb8

Please sign in to comment.