mirror of
https://github.com/go-gitea/gitea.git
synced 2024-05-11 05:55:29 +00:00
Backport #27987 by @yardenshoham Added the following characters to the regular expression for the email: - , - ; - ? - ! Also added a test case. - Fixes #27616 # Before  # After  Signed-off-by: Yarden Shoham <[email protected]> Co-authored-by: Yarden Shoham <[email protected]>
This commit is contained in:
co-authored by
GitHub
Yarden Shoham
parent
2978b435bb
commit
dfd960f22a
@@ -66,7 +66,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]{2,}(?:[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|$))")
|
||||
|
||||
// blackfriday extensions create IDs like fn:user-content-footnote
|
||||
blackfridayExtRegex = regexp.MustCompile(`[^:]*:user-content-`)
|
||||
|
||||
@@ -264,6 +264,18 @@ func TestRender_email(t *testing.T) {
|
||||
"send email to [email protected].",
|
||||
`<p>send email to <a href="mailto:[email protected]" rel="nofollow">[email protected]</a>.</p>`)
|
||||
|
||||
test(
|
||||
`[email protected],
|
||||
[email protected].
|
||||
[email protected];
|
||||
[email protected]?
|
||||
[email protected]!`,
|
||||
`<p><a href="mailto:[email protected]" rel="nofollow">[email protected]</a>,<br/>
|
||||
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>.<br/>
|
||||
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>;<br/>
|
||||
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>?<br/>
|
||||
<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>!</p>`)
|
||||
|
||||
// Test that should *not* be turned into email links
|
||||
test(
|
||||
"\"[email protected]\"",
|
||||
|
||||
Reference in New Issue
Block a user