From a1f01b0d7118318a9242ace206198a186367a594 Mon Sep 17 00:00:00 2001 From: Alexey Terentyev Date: Wed, 6 Jun 2018 03:52:48 +0300 Subject: [PATCH 1/3] Fixed the detection of URL links in the description (# 4143) Signed-off-by: Alexey Terentyev --- models/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/repo.go b/models/repo.go index c95c867f3..adbc015f5 100644 --- a/models/repo.go +++ b/models/repo.go @@ -783,7 +783,7 @@ func (repo *Repository) NextIssueIndex() int64 { } var ( - descPattern = regexp.MustCompile(`https?://\S+`) + descPattern = regexp.MustCompile(`https?://[a-zA-Z0-9-_@:;%.,+~#?&/=|!$]+`) ) // DescriptionHTML does special handles to description and return HTML string. From bf02f8d816184946ce73e2d6366e775eb90cb1ee Mon Sep 17 00:00:00 2001 From: Alexey Terentyev Date: Wed, 6 Jun 2018 05:38:06 +0300 Subject: [PATCH 2/3] Added test for DescriptionHTML Signed-off-by: Alexey Terentyev --- models/repo_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/models/repo_test.go b/models/repo_test.go index 752ffc2dd..44c9d9fea 100644 --- a/models/repo_test.go +++ b/models/repo_test.go @@ -5,6 +5,7 @@ package models import ( + "fmt" "path" "testing" @@ -176,3 +177,14 @@ func TestTransferOwnership(t *testing.T) { CheckConsistencyFor(t, &Repository{}, &User{}, &Team{}) } + +func TestRepoDescriptionHTML(t *testing.T) { + url := "https://github.com/go-gitea/gitea" + description := "GitHub repo: (%s)" + repo := &Repository{Description: fmt.Sprintf(description, url)} + + actual := repo.DescriptionHTML() + expected := fmt.Sprintf(description, + fmt.Sprintf(`%[1]s`, url)) + assert.EqualValues(t, expected, actual) +} From 637e65985556102cdd5df39b4d4518d12863ebb0 Mon Sep 17 00:00:00 2001 From: Alexey Terentyev Date: Wed, 6 Jun 2018 12:42:39 +0300 Subject: [PATCH 3/3] Fixed test Signed-off-by: Alexey Terentyev --- models/repo_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/repo_test.go b/models/repo_test.go index 44c9d9fea..cb4175f8f 100644 --- a/models/repo_test.go +++ b/models/repo_test.go @@ -185,6 +185,6 @@ func TestRepoDescriptionHTML(t *testing.T) { actual := repo.DescriptionHTML() expected := fmt.Sprintf(description, - fmt.Sprintf(`%[1]s`, url)) + fmt.Sprintf(`%[1]s`, url)) assert.EqualValues(t, expected, actual) }