Skip to content

Commit dfd960f

Browse files
Render email addresses as such if followed by punctuation (go-gitea#27987) (go-gitea#27991)
Backport go-gitea#27987 by @yardenshoham Added the following characters to the regular expression for the email: - , - ; - ? - ! Also added a test case. - Fixes go-gitea#27616 # Before ![image](https://github.com/go-gitea/gitea/assets/20454870/c57eac26-f281-43ef-a51d-9c9a81b63efa) # After ![image](https://github.com/go-gitea/gitea/assets/20454870/fc7d5c08-4350-4af0-a7f0-d1444d2d75af) Signed-off-by: Yarden Shoham <[email protected]> Co-authored-by: Yarden Shoham <[email protected]>
1 parent 2978b43 commit dfd960f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

modules/markup/html.go

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

7171
// blackfriday extensions create IDs like fn:user-content-footnote
7272
blackfridayExtRegex = regexp.MustCompile(`[^:]*:user-content-`)

modules/markup/html_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,18 @@ func TestRender_email(t *testing.T) {
264264
"send email to [email protected].",
265265
`<p>send email to <a href="mailto:[email protected]" rel="nofollow">[email protected]</a>.</p>`)
266266

267+
test(
268+
269+
270+
271+
272+
273+
`<p><a href="mailto:[email protected]" rel="nofollow">[email protected]</a>,<br/>
274+
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>.<br/>
275+
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>;<br/>
276+
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>?<br/>
277+
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>!</p>`)
278+
267279
// Test that should *not* be turned into email links
268280
test(
269281

0 commit comments

Comments
 (0)