@@ -53,38 +53,38 @@ var (
5353 // shortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax
5454 shortLinkPattern = regexp .MustCompile (`\[\[(.*?)\]\](\w*)` )
5555
56- // anySHA1Pattern splits url containing SHA into parts
56+ // anyHashPattern splits url containing SHA into parts
5757 anyHashPattern = regexp .MustCompile (`https?://(?:\S+/){4,5}([0-9a-f]{40,64})(/[-+~_%.a-zA-Z0-9/]+)?(#[-+~_%.a-zA-Z0-9]+)?` )
5858
5959 // comparePattern matches "http://domain/org/repo/compare/COMMIT1...COMMIT2#hash"
6060 comparePattern = regexp .MustCompile (`https?://(?:\S+/){4,5}([0-9a-f]{7,64})(\.\.\.?)([0-9a-f]{7,64})?(#[-+~_%.a-zA-Z0-9]+)?` )
6161
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]+:` )
6364
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:
6767 // http://spec.commonmark.org/0.28/#email-address
6868 // https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type%3Demail)
6969 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|$))" )
7070
71- // blackfriday extensions create IDs like fn:user-content-footnote
71+ // blackfridayExtRegex is for blackfriday extensions create IDs like fn:user-content-footnote
7272 blackfridayExtRegex = regexp .MustCompile (`[^:]*:user-content-` )
7373
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]+:` )
7676)
7777
7878// CSS class for action keywords (e.g. "closes: #1")
7979const keywordClass = "issue-keyword"
8080
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 )
8484}
8585
86- func IsLinkStr (link string ) bool {
87- return validLinksPattern .MatchString (link )
86+ func IsFullURLString (link string ) bool {
87+ return fullURLPattern .MatchString (link )
8888}
8989
9090// regexp for full links to issues/pulls
@@ -399,7 +399,7 @@ func visitNode(ctx *RenderContext, procs []processor, node *html.Node) {
399399 if attr .Key != "src" {
400400 continue
401401 }
402- if len (attr .Val ) > 0 && ! IsLinkStr (attr .Val ) && ! strings .HasPrefix (attr .Val , "data:image/" ) {
402+ if len (attr .Val ) > 0 && ! IsFullURLString (attr .Val ) && ! strings .HasPrefix (attr .Val , "data:image/" ) {
403403 attr .Val = util .URLJoin (ctx .Links .ResolveMediaLink (ctx .IsWiki ), attr .Val )
404404 }
405405 attr .Val = camoHandleLink (attr .Val )
@@ -650,7 +650,7 @@ func shortLinkProcessor(ctx *RenderContext, node *html.Node) {
650650 if equalPos := strings .IndexByte (v , '=' ); equalPos == - 1 {
651651 // There is no equal in this argument; this is a mandatory arg
652652 if props ["name" ] == "" {
653- if IsLinkStr (v ) {
653+ if IsFullURLString (v ) {
654654 // If we clearly see it is a link, we save it so
655655
656656 // But first we need to ensure, that if both mandatory args provided
@@ -725,7 +725,7 @@ func shortLinkProcessor(ctx *RenderContext, node *html.Node) {
725725 DataAtom : atom .A ,
726726 }
727727 childNode .Parent = linkNode
728- absoluteLink := IsLinkStr (link )
728+ absoluteLink := IsFullURLString (link )
729729 if ! absoluteLink {
730730 if image {
731731 link = strings .ReplaceAll (link , " " , "+" )
@@ -1059,7 +1059,7 @@ func emojiShortCodeProcessor(ctx *RenderContext, node *html.Node) {
10591059 start := 0
10601060 next := node .NextSibling
10611061 for node != nil && node != next && start < len (node .Data ) {
1062- m := EmojiShortCodeRegex .FindStringSubmatchIndex (node .Data [start :])
1062+ m := emojiShortCodeRegex .FindStringSubmatchIndex (node .Data [start :])
10631063 if m == nil {
10641064 return
10651065 }
0 commit comments