diff --git a/modules/markup/html.go b/modules/markup/html.go index 383525477..1dc6627f2 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -405,6 +405,9 @@ func RenderShortLinks(rawBytes []byte, urlPrefix string, noLink bool, isWikiMark } else { link = strings.Replace(link, " ", "-", -1) } + if !strings.Contains(link, "/") { + link = url.PathEscape(link) + } } if image { if !absoluteLink { diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index 9ca3de01c..c7a97813b 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -55,10 +55,16 @@ func TestRender_ShortLinks(t *testing.T) { rawtree := markup.URLJoin(AppSubURL, "raw", "master") url := markup.URLJoin(tree, "Link") otherUrl := markup.URLJoin(tree, "OtherLink") + encodedURL := markup.URLJoin(tree, "Link%3F") imgurl := markup.URLJoin(rawtree, "Link.jpg") + encodedImgurl := markup.URLJoin(rawtree, "Link+%23.jpg") + notencodedImgurl := markup.URLJoin(rawtree, "some", "path", "Link+#.jpg") urlWiki := markup.URLJoin(AppSubURL, "wiki", "Link") otherUrlWiki := markup.URLJoin(AppSubURL, "wiki", "OtherLink") + encodedURLWiki := markup.URLJoin(AppSubURL, "wiki", "Link%3F") imgurlWiki := markup.URLJoin(AppSubURL, "wiki", "raw", "Link.jpg") + encodedImgurlWiki := markup.URLJoin(AppSubURL, "wiki", "raw", "Link+%23.jpg") + notencodedImgurlWiki := markup.URLJoin(AppSubURL, "wiki", "raw", "some", "path", "Link+#.jpg") favicon := "http://google.com/favicon.ico" test( @@ -101,6 +107,26 @@ func TestRender_ShortLinks(t *testing.T) { "[[Link]] [[OtherLink]]", `

Link OtherLink

`, `

Link OtherLink

`) + test( + "[[Link?]]", + `

Link?

`, + `

Link?

`) + test( + "[[Link]] [[OtherLink]] [[Link?]]", + `

Link OtherLink Link?

`, + `

Link OtherLink Link?

`) + test( + "[[Link #.jpg]]", + `

`, + `

`) + test( + "[[Name|Link #.jpg|alt=\"AltName\"|title='Title']]", + `

AltName

`, + `

AltName

`) + test( + "[[some/path/Link #.jpg]]", + `

`, + `

`) } func TestMisc_IsMarkdownFile(t *testing.T) {