Skip to content

Commit d05150a

Browse files
michaelkuhnlafriks
authored andcommitted
Make short link pattern greedy (#2259)
Multiple links on the same line are currently not recognized correctly.
1 parent a326263 commit d05150a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

modules/markdown/markdown.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var (
6464
Sha1CurrentPattern = regexp.MustCompile(`(?:^|\s|\()([0-9a-f]{7,40})\b`)
6565

6666
// ShortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax
67-
ShortLinkPattern = regexp.MustCompile(`(\[\[.*\]\]\w*)`)
67+
ShortLinkPattern = regexp.MustCompile(`(\[\[.*?\]\]\w*)`)
6868

6969
// AnySHA1Pattern allows to split url containing SHA into parts
7070
AnySHA1Pattern = regexp.MustCompile(`(http\S*)://(\S+)/(\S+)/(\S+)/(\S+)/([0-9a-f]{40})(?:/?([^#\s]+)?(?:#(\S+))?)?`)

modules/markdown/markdown_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,10 @@ func TestRender_ShortLinks(t *testing.T) {
260260

261261
rawtree := URLJoin(AppSubURL, "raw", "master")
262262
url := URLJoin(tree, "Link")
263+
otherUrl := URLJoin(tree, "OtherLink")
263264
imgurl := URLJoin(rawtree, "Link.jpg")
264265
urlWiki := URLJoin(AppSubURL, "wiki", "Link")
266+
otherUrlWiki := URLJoin(AppSubURL, "wiki", "OtherLink")
265267
imgurlWiki := URLJoin(AppSubURL, "wiki", "raw", "Link.jpg")
266268
favicon := "http://google.com/favicon.ico"
267269

@@ -301,6 +303,10 @@ func TestRender_ShortLinks(t *testing.T) {
301303
"[[Name|Link.jpg|alt=\"AltName\"|title='Title']]",
302304
`<p><a href="`+imgurl+`" rel="nofollow"><img src="`+imgurl+`" alt="AltName" title="Title"/></a></p>`,
303305
`<p><a href="`+imgurlWiki+`" rel="nofollow"><img src="`+imgurlWiki+`" alt="AltName" title="Title"/></a></p>`)
306+
test(
307+
"[[Link]] [[OtherLink]]",
308+
`<p><a href="`+url+`" rel="nofollow">Link</a> <a href="`+otherUrl+`" rel="nofollow">OtherLink</a></p>`,
309+
`<p><a href="`+urlWiki+`" rel="nofollow">Link</a> <a href="`+otherUrlWiki+`" rel="nofollow">OtherLink</a></p>`)
304310
}
305311

306312
func TestRender_Commits(t *testing.T) {

0 commit comments

Comments
 (0)