Fix domain name pattern in email regex (#6739)

Fixes #6735
This commit is contained in:
mrsdizzie
2019-04-24 21:53:41 -04:00
committed by techknowlogick
parent 6a58832286
commit 0064535ad2
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -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?://")
)
+15
View File
@@ -176,6 +176,9 @@ func TestRender_email(t *testing.T) {
test(
"[email protected].",
`<p><a href="mailto:[email protected]" rel="nofollow">[email protected]</a>.</p>`)
test(
"[email protected]",
`<p><a href="mailto:[email protected]" rel="nofollow">[email protected]</a></p>`)
test(
"send email to [email protected].",
`<p>send email to <a href="mailto:[email protected]" rel="nofollow">[email protected]</a>.</p>`)
@@ -190,6 +193,18 @@ func TestRender_email(t *testing.T) {
test(
"[email protected]:go-gitea/gitea.git",
`<p>[email protected]:go-gitea/gitea.git</p>`)
test(
"gitea@3",
`<p>gitea@3</p>`)
test(
"[email protected]",
`<p>[email protected]</p>`)
test(
"email@[email protected]",
`<p>email@[email protected]</p>`)
test(
"[email protected]",
`<p>[email protected]</p>`)
}
func TestRender_ShortLinks(t *testing.T) {