Skip to content

Commit 0064535

Browse files
mrsdizzietechknowlogick
authored andcommitted
Fix domain name pattern in email regex (#6739)
Fixes #6735
1 parent 6a58832 commit 0064535

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

modules/markup/html.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var (
6363
// well as the HTML5 spec:
6464
// http://spec.commonmark.org/0.28/#email-address
6565
// https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type%3Demail)
66-
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|$))")
66+
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|$))")
6767

6868
linkRegex, _ = xurls.StrictMatchingScheme("https?://")
6969
)

modules/markup/html_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ func TestRender_email(t *testing.T) {
176176
test(
177177
178178
`<p><a href="mailto:[email protected]" rel="nofollow">[email protected]</a>.</p>`)
179+
test(
180+
181+
`<p><a href="mailto:[email protected]" rel="nofollow">[email protected]</a></p>`)
179182
test(
180183
"send email to [email protected].",
181184
`<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) {
190193
test(
191194
"[email protected]:go-gitea/gitea.git",
192195
`<p>[email protected]:go-gitea/gitea.git</p>`)
196+
test(
197+
"gitea@3",
198+
`<p>gitea@3</p>`)
199+
test(
200+
201+
202+
test(
203+
204+
`<p>email@[email protected]</p>`)
205+
test(
206+
207+
193208
}
194209

195210
func TestRender_ShortLinks(t *testing.T) {

0 commit comments

Comments
 (0)