@@ -53,38 +53,38 @@ var (
53
53
// shortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax
54
54
shortLinkPattern = regexp .MustCompile (`\[\[(.*?)\]\](\w*)` )
55
55
56
- // anySHA1Pattern splits url containing SHA into parts
56
+ // anyHashPattern splits url containing SHA into parts
57
57
anyHashPattern = regexp .MustCompile (`https?://(?:\S+/){4,5}([0-9a-f]{40,64})(/[-+~_%.a-zA-Z0-9/]+)?(#[-+~_%.a-zA-Z0-9]+)?` )
58
58
59
59
// comparePattern matches "http://domain/org/repo/compare/COMMIT1...COMMIT2#hash"
60
60
comparePattern = regexp .MustCompile (`https?://(?:\S+/){4,5}([0-9a-f]{7,64})(\.\.\.?)([0-9a-f]{7,64})?(#[-+~_%.a-zA-Z0-9]+)?` )
61
61
62
- validLinksPattern = regexp .MustCompile (`^[a-z][\w-]+://` )
62
+ // fullURLPattern matches full URL like "mailto:...", "https://..." and "ssh+git://..."
63
+ fullURLPattern = regexp .MustCompile (`^[a-z][-+\w]+:` )
63
64
64
- // While this email regex is definitely not perfect and I'm sure you can come up
65
- // with edge cases, it is still accepted by the CommonMark specification, as
66
- // well as the HTML5 spec:
65
+ // emailRegex is definitely not perfect with edge cases,
66
+ // it is still accepted by the CommonMark specification, as well as the HTML5 spec:
67
67
// http://spec.commonmark.org/0.28/#email-address
68
68
// https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type%3Demail)
69
69
emailRegex = regexp .MustCompile ("(?:\\ s|^|\\ (|\\ [)([a-zA-Z0-9.!#$%&'*+\\ /=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\ .[a-zA-Z0-9]{2,}(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+)(?:\\ s|$|\\ )|\\ ]|;|,|\\ ?|!|\\ .(\\ s|$))" )
70
70
71
- // blackfriday extensions create IDs like fn:user-content-footnote
71
+ // blackfridayExtRegex is for blackfriday extensions create IDs like fn:user-content-footnote
72
72
blackfridayExtRegex = regexp .MustCompile (`[^:]*:user-content-` )
73
73
74
- // EmojiShortCodeRegex find emoji by alias like :smile:
75
- EmojiShortCodeRegex = regexp .MustCompile (`:[-+\w]+:` )
74
+ // emojiShortCodeRegex find emoji by alias like :smile:
75
+ emojiShortCodeRegex = regexp .MustCompile (`:[-+\w]+:` )
76
76
)
77
77
78
78
// CSS class for action keywords (e.g. "closes: #1")
79
79
const keywordClass = "issue-keyword"
80
80
81
- // IsLink reports whether link fits valid format.
82
- func IsLink (link []byte ) bool {
83
- return validLinksPattern .Match (link )
81
+ // IsFullURLBytes reports whether link fits valid format.
82
+ func IsFullURLBytes (link []byte ) bool {
83
+ return fullURLPattern .Match (link )
84
84
}
85
85
86
- func IsLinkStr (link string ) bool {
87
- return validLinksPattern .MatchString (link )
86
+ func IsFullURLString (link string ) bool {
87
+ return fullURLPattern .MatchString (link )
88
88
}
89
89
90
90
// regexp for full links to issues/pulls
@@ -399,7 +399,7 @@ func visitNode(ctx *RenderContext, procs []processor, node *html.Node) {
399
399
if attr .Key != "src" {
400
400
continue
401
401
}
402
- if len ( attr . Val ) > 0 && ! IsLinkStr (attr .Val ) && ! strings .HasPrefix (attr .Val , "data:image/" ) {
402
+ if ! IsFullURLString (attr .Val ) && ! strings .HasPrefix (attr .Val , "data:image/" ) {
403
403
attr .Val = util .URLJoin (ctx .Links .ResolveMediaLink (ctx .IsWiki ), attr .Val )
404
404
}
405
405
attr .Val = camoHandleLink (attr .Val )
@@ -650,7 +650,7 @@ func shortLinkProcessor(ctx *RenderContext, node *html.Node) {
650
650
if equalPos := strings .IndexByte (v , '=' ); equalPos == - 1 {
651
651
// There is no equal in this argument; this is a mandatory arg
652
652
if props ["name" ] == "" {
653
- if IsLinkStr (v ) {
653
+ if IsFullURLString (v ) {
654
654
// If we clearly see it is a link, we save it so
655
655
656
656
// But first we need to ensure, that if both mandatory args provided
@@ -725,7 +725,7 @@ func shortLinkProcessor(ctx *RenderContext, node *html.Node) {
725
725
DataAtom : atom .A ,
726
726
}
727
727
childNode .Parent = linkNode
728
- absoluteLink := IsLinkStr (link )
728
+ absoluteLink := IsFullURLString (link )
729
729
if ! absoluteLink {
730
730
if image {
731
731
link = strings .ReplaceAll (link , " " , "+" )
@@ -1059,7 +1059,7 @@ func emojiShortCodeProcessor(ctx *RenderContext, node *html.Node) {
1059
1059
start := 0
1060
1060
next := node .NextSibling
1061
1061
for node != nil && node != next && start < len (node .Data ) {
1062
- m := EmojiShortCodeRegex .FindStringSubmatchIndex (node .Data [start :])
1062
+ m := emojiShortCodeRegex .FindStringSubmatchIndex (node .Data [start :])
1063
1063
if m == nil {
1064
1064
return
1065
1065
}
0 commit comments