Fix wiki inter-links with cases and add tests for this case (#3560)

This commit is contained in:
Chaz Reid 2018-03-05 10:39:12 -08:00 committed by Lauris BH
parent 171914e9a7
commit 69ea5e4385
2 changed files with 16 additions and 6 deletions

View File

@ -464,7 +464,11 @@ func shortLinkProcessorFull(ctx *postProcessCtx, node *html.Node, noLink bool) {
childNode.Parent = linkNode childNode.Parent = linkNode
absoluteLink := isLinkStr(link) absoluteLink := isLinkStr(link)
if !absoluteLink { if !absoluteLink {
link = strings.Replace(link, " ", "+", -1) if image {
link = strings.Replace(link, " ", "+", -1)
} else {
link = strings.Replace(link, " ", "-", -1)
}
} }
urlPrefix := ctx.urlPrefix urlPrefix := ctx.urlPrefix
if image { if image {

View File

@ -81,11 +81,13 @@ func TestRender_ShortLinks(t *testing.T) {
rawtree := util.URLJoin(AppSubURL, "raw", "master") rawtree := util.URLJoin(AppSubURL, "raw", "master")
url := util.URLJoin(tree, "Link") url := util.URLJoin(tree, "Link")
otherURL := util.URLJoin(tree, "OtherLink") otherURL := util.URLJoin(tree, "Other-Link")
imgurl := util.URLJoin(rawtree, "Link.jpg") imgurl := util.URLJoin(rawtree, "Link.jpg")
otherImgurl := util.URLJoin(rawtree, "Link+Other.jpg")
urlWiki := util.URLJoin(AppSubURL, "wiki", "Link") urlWiki := util.URLJoin(AppSubURL, "wiki", "Link")
otherURLWiki := util.URLJoin(AppSubURL, "wiki", "OtherLink") otherURLWiki := util.URLJoin(AppSubURL, "wiki", "Other-Link")
imgurlWiki := util.URLJoin(AppSubURL, "wiki", "raw", "Link.jpg") imgurlWiki := util.URLJoin(AppSubURL, "wiki", "raw", "Link.jpg")
otherImgurlWiki := util.URLJoin(AppSubURL, "wiki", "raw", "Link+Other.jpg")
favicon := "http://google.com/favicon.ico" favicon := "http://google.com/favicon.ico"
test( test(
@ -125,7 +127,11 @@ func TestRender_ShortLinks(t *testing.T) {
`<p><a href="`+imgurl+`" rel="nofollow"><img src="`+imgurl+`" title="Title" alt="AltName"/></a></p>`, `<p><a href="`+imgurl+`" rel="nofollow"><img src="`+imgurl+`" title="Title" alt="AltName"/></a></p>`,
`<p><a href="`+imgurlWiki+`" rel="nofollow"><img src="`+imgurlWiki+`" title="Title" alt="AltName"/></a></p>`) `<p><a href="`+imgurlWiki+`" rel="nofollow"><img src="`+imgurlWiki+`" title="Title" alt="AltName"/></a></p>`)
test( test(
"[[Link]] [[OtherLink]]", "[[Name|Link Other.jpg|alt=\"AltName\"|title='Title']]",
`<p><a href="`+url+`" rel="nofollow">Link</a> <a href="`+otherURL+`" rel="nofollow">OtherLink</a></p>`, `<p><a href="`+otherImgurl+`" rel="nofollow"><img src="`+otherImgurl+`" title="Title" alt="AltName"/></a></p>`,
`<p><a href="`+urlWiki+`" rel="nofollow">Link</a> <a href="`+otherURLWiki+`" rel="nofollow">OtherLink</a></p>`) `<p><a href="`+otherImgurlWiki+`" rel="nofollow"><img src="`+otherImgurlWiki+`" title="Title" alt="AltName"/></a></p>`)
test(
"[[Link]] [[Other Link]]",
`<p><a href="`+url+`" rel="nofollow">Link</a> <a href="`+otherURL+`" rel="nofollow">Other Link</a></p>`,
`<p><a href="`+urlWiki+`" rel="nofollow">Link</a> <a href="`+otherURLWiki+`" rel="nofollow">Other Link</a></p>`)
} }