summaryrefslogtreecommitdiffstats
path: root/modules/markup/html.go
diff options
context:
space:
mode:
authorRafael <git@rafael.ovh>2024-04-10 18:49:57 +0100
committerGitHub <noreply@github.com>2024-04-10 17:49:57 +0000
commitc1f76aea45f11e1d5ae22c047cf3bda9c681de8d (patch)
treeebf837b7b527c2eb79a27dbb08803a1c696f930b /modules/markup/html.go
parent50099d7af436785daf66a3a9f27bd5c009f90684 (diff)
downloadgitea-c1f76aea45f11e1d5ae22c047cf3bda9c681de8d.tar.gz
gitea-c1f76aea45f11e1d5ae22c047cf3bda9c681de8d.zip
Use raw Wiki links for non-renderable Wiki files (#30273)
In Wiki pages, short-links created to local Wiki files were always expanded as regular Wiki Links. In particular, if a link wanted to point to a file that Gitea doesn't know how to render (e.g, a .zip file), a user following the link would be silently redirected to the Wiki's home page. This change makes short-links* in Wiki pages be expanded to raw wiki links, so these local wiki files may be accessed without manually accessing their URL. * only short-links ending in a file extension that isn't renderable are affected. Closes #27121. Signed-off-by: Rafael GirĂ£o <rafael.s.girao@tecnico.ulisboa.pt> Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'modules/markup/html.go')
-rw-r--r--modules/markup/html.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go
index 56aa1cb49c..cef643bf18 100644
--- a/modules/markup/html.go
+++ b/modules/markup/html.go
@@ -709,7 +709,8 @@ func shortLinkProcessor(ctx *RenderContext, node *html.Node) {
name += tail
image := false
- switch ext := filepath.Ext(link); ext {
+ ext := filepath.Ext(link)
+ switch ext {
// fast path: empty string, ignore
case "":
// leave image as false
@@ -767,11 +768,26 @@ func shortLinkProcessor(ctx *RenderContext, node *html.Node) {
}
} else {
if !absoluteLink {
+ var base string
if ctx.IsWiki {
- link = util.URLJoin(ctx.Links.WikiLink(), link)
+ switch ext {
+ case "":
+ // no file extension, create a regular wiki link
+ base = ctx.Links.WikiLink()
+ default:
+ // we have a file extension:
+ // return a regular wiki link if it's a renderable file (extension),
+ // raw link otherwise
+ if Type(link) != "" {
+ base = ctx.Links.WikiLink()
+ } else {
+ base = ctx.Links.WikiRawLink()
+ }
+ }
} else {
- link = util.URLJoin(ctx.Links.SrcLink(), link)
+ base = ctx.Links.SrcLink()
}
+ link = util.URLJoin(base, link)
}
childNode.Type = html.TextNode
childNode.Data = name