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>
This commit is contained in:
parent
50099d7af4
commit
c1f76aea45
12 changed files with 65 additions and 23 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue