Gitea: Wiki links do not handle spaces correctly

Created on 13 Feb 2018  路  2Comments  路  Source: go-gitea/gitea

Description

A link like [[My Article]] links to My+Article.md where it rather should link to My-Article.md. The Sidebar links in the above copy of the microsoft/vscode-wiki are a good example.

kinbug

Most helpful comment

Looks like the relevant wiki template file is templates/repo/wiki/view.tmpl on line 88, which contains:

{{.sidebarContent | Str2html}}

Str2html is a Go library imported by helper.go that turns markdown into HTML. It is unlikely the links are being improperly rendered by Str2html.

The sidebarContent variable is loaded and set in wiki.go.

This loads the sidebar content from wikiContentsByName() (later in the same wiki.go file).

It renders the final sidebar content by calling markdown.RenderWiki(), which just calls markup.RenderWiki in markup.go. This, in turn, calls a couple of layers of render functions, all in markup.go, until we get to the render() function in markup.go, which contains the culprit line:

func render(parser Parser, rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte {
    urlPrefix = strings.Replace(urlPrefix, " ", "+", -1) /* <----- O NOES !!!!!! */
    result := parser.Render(rawBytes, urlPrefix, metas, isWiki)
    result = PostProcess(result, urlPrefix, metas, isWiki)
    return SanitizeBytes(result)
}

All 2 comments

Looks like the relevant wiki template file is templates/repo/wiki/view.tmpl on line 88, which contains:

{{.sidebarContent | Str2html}}

Str2html is a Go library imported by helper.go that turns markdown into HTML. It is unlikely the links are being improperly rendered by Str2html.

The sidebarContent variable is loaded and set in wiki.go.

This loads the sidebar content from wikiContentsByName() (later in the same wiki.go file).

It renders the final sidebar content by calling markdown.RenderWiki(), which just calls markup.RenderWiki in markup.go. This, in turn, calls a couple of layers of render functions, all in markup.go, until we get to the render() function in markup.go, which contains the culprit line:

func render(parser Parser, rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte {
    urlPrefix = strings.Replace(urlPrefix, " ", "+", -1) /* <----- O NOES !!!!!! */
    result := parser.Render(rawBytes, urlPrefix, metas, isWiki)
    result = PostProcess(result, urlPrefix, metas, isWiki)
    return SanitizeBytes(result)
}

@charlesreid1 you are awesome. Thanks for the detailed explanation, too!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lunny picture lunny  路  3Comments

Fastidious picture Fastidious  路  3Comments

kolargol picture kolargol  路  3Comments

lunny picture lunny  路  3Comments

kifirkin picture kifirkin  路  3Comments