From 0064535ad28f85fb8c84a0237ea02bd432c6a1f6 Mon Sep 17 00:00:00 2001 From: mrsdizzie Date: Wed, 24 Apr 2019 21:53:42 -0400 Subject: [PATCH] Fix domain name pattern in email regex (#6739) Fixes #6735 --- modules/markup/html.go | 2 +- modules/markup/html_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index adc2bef53..91913b067 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -63,7 +63,7 @@ var ( // well as the HTML5 spec: // http://spec.commonmark.org/0.28/#email-address // https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type%3Demail) - emailRegex = regexp.MustCompile("(?:\\s|^|\\(|\\[)([a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)(?:\\s|$|\\)|\\]|\\.(\\s|$))") + emailRegex = regexp.MustCompile("(?:\\s|^|\\(|\\[)([a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9]{2,}(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+)(?:\\s|$|\\)|\\]|\\.(\\s|$))") linkRegex, _ = xurls.StrictMatchingScheme("https?://") ) diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 543db1d46..daf953c9e 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -176,6 +176,9 @@ func TestRender_email(t *testing.T) { test( "info@gitea.com.", `

info@gitea.com.

`) + test( + "firstname+lastname@gitea.com", + `

firstname+lastname@gitea.com

`) test( "send email to info@gitea.co.uk.", `

send email to info@gitea.co.uk.

`) @@ -190,6 +193,18 @@ func TestRender_email(t *testing.T) { test( "git@try.gitea.io:go-gitea/gitea.git", `

git@try.gitea.io:go-gitea/gitea.git

`) + test( + "gitea@3", + `

gitea@3

`) + test( + "gitea@gmail.c", + `

gitea@gmail.c

`) + test( + "email@domain@domain.com", + `

email@domain@domain.com

`) + test( + "email@domain..com", + `

email@domain..com

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