From d05150a3317766863586b3a5b2a6a09feab3dd8c Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Sat, 5 Aug 2017 23:52:19 +0200 Subject: [PATCH] Make short link pattern greedy (#2259) Multiple links on the same line are currently not recognized correctly. --- modules/markdown/markdown.go | 2 +- modules/markdown/markdown_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/markdown/markdown.go b/modules/markdown/markdown.go index bebf454ff1..898df59292 100644 --- a/modules/markdown/markdown.go +++ b/modules/markdown/markdown.go @@ -64,7 +64,7 @@ var ( Sha1CurrentPattern = regexp.MustCompile(`(?:^|\s|\()([0-9a-f]{7,40})\b`) // ShortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax - ShortLinkPattern = regexp.MustCompile(`(\[\[.*\]\]\w*)`) + ShortLinkPattern = regexp.MustCompile(`(\[\[.*?\]\]\w*)`) // AnySHA1Pattern allows to split url containing SHA into parts AnySHA1Pattern = regexp.MustCompile(`(http\S*)://(\S+)/(\S+)/(\S+)/(\S+)/([0-9a-f]{40})(?:/?([^#\s]+)?(?:#(\S+))?)?`) diff --git a/modules/markdown/markdown_test.go b/modules/markdown/markdown_test.go index 2943ffde95..cfe9c5421a 100644 --- a/modules/markdown/markdown_test.go +++ b/modules/markdown/markdown_test.go @@ -260,8 +260,10 @@ func TestRender_ShortLinks(t *testing.T) { rawtree := URLJoin(AppSubURL, "raw", "master") url := URLJoin(tree, "Link") + otherUrl := URLJoin(tree, "OtherLink") imgurl := URLJoin(rawtree, "Link.jpg") urlWiki := URLJoin(AppSubURL, "wiki", "Link") + otherUrlWiki := URLJoin(AppSubURL, "wiki", "OtherLink") imgurlWiki := URLJoin(AppSubURL, "wiki", "raw", "Link.jpg") favicon := "http://google.com/favicon.ico" @@ -301,6 +303,10 @@ func TestRender_ShortLinks(t *testing.T) { "[[Name|Link.jpg|alt=\"AltName\"|title='Title']]", `

AltName

`, `

AltName

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

Link OtherLink

`, + `

Link OtherLink

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