@@ -144,20 +144,6 @@ func CustomLinkURLSchemes(schemes []string) {
144144 common .LinkRegex , _ = xurls .StrictMatchingScheme (strings .Join (withAuth , "|" ))
145145}
146146
147- // IsSameDomain checks if given url string has the same hostname as current Gitea instance
148- func IsSameDomain (s string ) bool {
149- if strings .HasPrefix (s , "/" ) {
150- return true
151- }
152- if uapp , err := url .Parse (setting .AppURL ); err == nil {
153- if u , err := url .Parse (s ); err == nil {
154- return u .Host == uapp .Host
155- }
156- return false
157- }
158- return false
159- }
160-
161147type postProcessError struct {
162148 context string
163149 err error
@@ -429,7 +415,7 @@ func visitNode(ctx *RenderContext, procs []processor, node *html.Node) *html.Nod
429415 // We ignore code and pre.
430416 switch node .Type {
431417 case html .TextNode :
432- textNode (ctx , procs , node )
418+ processTextNodes (ctx , procs , node )
433419 case html .ElementNode :
434420 if node .Data == "img" {
435421 next := node .NextSibling
@@ -465,15 +451,16 @@ func visitNode(ctx *RenderContext, procs []processor, node *html.Node) *html.Nod
465451 for n := node .FirstChild ; n != nil ; {
466452 n = visitNode (ctx , procs , n )
467453 }
454+ default :
468455 }
469456 return node .NextSibling
470457}
471458
472- // textNode runs the passed node through various processors, in order to handle
459+ // processTextNodes runs the passed node through various processors, in order to handle
473460// all kinds of special links handled by the post-processing.
474- func textNode (ctx * RenderContext , procs []processor , node * html.Node ) {
475- for _ , processor := range procs {
476- processor (ctx , node )
461+ func processTextNodes (ctx * RenderContext , procs []processor , node * html.Node ) {
462+ for _ , p := range procs {
463+ p (ctx , node )
477464 }
478465}
479466
@@ -761,10 +748,10 @@ func shortLinkProcessor(ctx *RenderContext, node *html.Node) {
761748 if image {
762749 link = strings .ReplaceAll (link , " " , "+" )
763750 } else {
764- link = strings .ReplaceAll (link , " " , "-" )
751+ link = strings .ReplaceAll (link , " " , "-" ) // FIXME: it should support dashes in the link, eg: "the-dash-support.-"
765752 }
766753 if ! strings .Contains (link , "/" ) {
767- link = url .PathEscape (link )
754+ link = url .PathEscape (link ) // FIXME: it doesn't seem right and it might cause double-escaping
768755 }
769756 }
770757 if image {
@@ -796,28 +783,7 @@ func shortLinkProcessor(ctx *RenderContext, node *html.Node) {
796783 childNode .Attr = childNode .Attr [:2 ]
797784 }
798785 } else {
799- if ! absoluteLink {
800- var base string
801- if ctx .IsWiki {
802- switch ext {
803- case "" :
804- // no file extension, create a regular wiki link
805- base = ctx .Links .WikiLink ()
806- default :
807- // we have a file extension:
808- // return a regular wiki link if it's a renderable file (extension),
809- // raw link otherwise
810- if Type (link ) != "" {
811- base = ctx .Links .WikiLink ()
812- } else {
813- base = ctx .Links .WikiRawLink ()
814- }
815- }
816- } else {
817- base = ctx .Links .SrcLink ()
818- }
819- link = util .URLJoin (base , link )
820- }
786+ link , _ = ResolveLink (ctx , link , "" )
821787 childNode .Type = html .TextNode
822788 childNode .Data = name
823789 }
@@ -939,14 +905,11 @@ func issueIndexPatternProcessor(ctx *RenderContext, node *html.Node) {
939905 // Path determines the type of link that will be rendered. It's unknown at this point whether
940906 // the linked item is actually a PR or an issue. Luckily it's of no real consequence because
941907 // Gitea will redirect on click as appropriate.
942- path := "issues"
943- if ref .IsPull {
944- path = "pulls"
945- }
908+ issuePath := util .Iif (ref .IsPull , "pulls" , "issues" )
946909 if ref .Owner == "" {
947- link = createLink (util .URLJoin (ctx .Links .Prefix (), ctx .Metas ["user" ], ctx .Metas ["repo" ], path , ref .Issue ), reftext , "ref-issue" )
910+ link = createLink (util .URLJoin (ctx .Links .Prefix (), ctx .Metas ["user" ], ctx .Metas ["repo" ], issuePath , ref .Issue ), reftext , "ref-issue" )
948911 } else {
949- link = createLink (util .URLJoin (ctx .Links .Prefix (), ref .Owner , ref .Name , path , ref .Issue ), reftext , "ref-issue" )
912+ link = createLink (util .URLJoin (ctx .Links .Prefix (), ref .Owner , ref .Name , issuePath , ref .Issue ), reftext , "ref-issue" )
950913 }
951914 }
952915
@@ -1207,7 +1170,7 @@ func hashCurrentPatternProcessor(ctx *RenderContext, node *html.Node) {
12071170 return
12081171 }
12091172 ctx .AddCancel (func () {
1210- closer .Close ()
1173+ _ = closer .Close ()
12111174 ctx .GitRepo = nil
12121175 })
12131176 }
0 commit comments