Skip to content

Commit 69ea5e4

Browse files
charlesreid1lafriks
authored andcommitted
Fix wiki inter-links with cases and add tests for this case (#3560)
1 parent 171914e commit 69ea5e4

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

modules/markup/html.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,11 @@ func shortLinkProcessorFull(ctx *postProcessCtx, node *html.Node, noLink bool) {
464464
childNode.Parent = linkNode
465465
absoluteLink := isLinkStr(link)
466466
if !absoluteLink {
467-
link = strings.Replace(link, " ", "+", -1)
467+
if image {
468+
link = strings.Replace(link, " ", "+", -1)
469+
} else {
470+
link = strings.Replace(link, " ", "-", -1)
471+
}
468472
}
469473
urlPrefix := ctx.urlPrefix
470474
if image {

modules/markup/html_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ func TestRender_ShortLinks(t *testing.T) {
8181

8282
rawtree := util.URLJoin(AppSubURL, "raw", "master")
8383
url := util.URLJoin(tree, "Link")
84-
otherURL := util.URLJoin(tree, "OtherLink")
84+
otherURL := util.URLJoin(tree, "Other-Link")
8585
imgurl := util.URLJoin(rawtree, "Link.jpg")
86+
otherImgurl := util.URLJoin(rawtree, "Link+Other.jpg")
8687
urlUncyclo := util.URLJoin(AppSubURL, "wiki", "Link")
87-
otherURLUncyclo := util.URLJoin(AppSubURL, "wiki", "OtherLink")
88+
otherURLUncyclo := util.URLJoin(AppSubURL, "wiki", "Other-Link")
8889
imgurlUncyclo := util.URLJoin(AppSubURL, "wiki", "raw", "Link.jpg")
90+
otherImgurlUncyclo := util.URLJoin(AppSubURL, "wiki", "raw", "Link+Other.jpg")
8991
favicon := "http://google.com/favicon.ico"
9092

9193
test(
@@ -125,7 +127,11 @@ func TestRender_ShortLinks(t *testing.T) {
125127
`<p><a href="`+imgurl+`" rel="nofollow"><img src="`+imgurl+`" title="Title" alt="AltName"/></a></p>`,
126128
`<p><a href="`+imgurlUncyclo+`" rel="nofollow"><img src="`+imgurlUncyclo+`" title="Title" alt="AltName"/></a></p>`)
127129
test(
128-
"[[Link]] [[OtherLink]]",
129-
`<p><a href="`+url+`" rel="nofollow">Link</a> <a href="`+otherURL+`" rel="nofollow">OtherLink</a></p>`,
130-
`<p><a href="`+urlUncyclo+`" rel="nofollow">Link</a> <a href="`+otherURLUncyclo+`" rel="nofollow">OtherLink</a></p>`)
130+
"[[Name|Link Other.jpg|alt=\"AltName\"|title='Title']]",
131+
`<p><a href="`+otherImgurl+`" rel="nofollow"><img src="`+otherImgurl+`" title="Title" alt="AltName"/></a></p>`,
132+
`<p><a href="`+otherImgurlUncyclo+`" rel="nofollow"><img src="`+otherImgurlUncyclo+`" title="Title" alt="AltName"/></a></p>`)
133+
test(
134+
"[[Link]] [[Other Link]]",
135+
`<p><a href="`+url+`" rel="nofollow">Link</a> <a href="`+otherURL+`" rel="nofollow">Other Link</a></p>`,
136+
`<p><a href="`+urlUncyclo+`" rel="nofollow">Link</a> <a href="`+otherURLUncyclo+`" rel="nofollow">Other Link</a></p>`)
131137
}

0 commit comments

Comments
 (0)