diff options
author | Giteabot <teabot@gitea.io> | 2023-11-11 13:26:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-11 13:26:18 +0800 |
commit | 2691b345e6a6de58777fe9671b12fe8503d39c5d (patch) | |
tree | 971aa6e56f9f0b793655ecb91f69dd6d57aa379a /modules/markup | |
parent | 60b51d0648533de1c7eef543004bf5bd5fb93c7c (diff) | |
download | gitea-2691b345e6a6de58777fe9671b12fe8503d39c5d.tar.gz gitea-2691b345e6a6de58777fe9671b12fe8503d39c5d.zip |
Render email addresses as such if followed by punctuation (#27987) (#27992)
Backport #27987 by @yardenshoham
Added the following characters to the regular expression for the email:
- ,
- ;
- ?
- !
Also added a test case.
- Fixes #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 <git@yardenshoham.com>
Co-authored-by: Yarden Shoham <git@yardenshoham.com>
Diffstat (limited to 'modules/markup')
-rw-r--r-- | modules/markup/html.go | 2 | ||||
-rw-r--r-- | modules/markup/html_test.go | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go index e53ccc6a79..774cbe1557 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -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-`) diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 9156bc6331..8b9ed44db6 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -264,6 +264,18 @@ func TestRender_email(t *testing.T) { "send email to info@gitea.co.uk.", `<p>send email to <a href="mailto:info@gitea.co.uk" rel="nofollow">info@gitea.co.uk</a>.</p>`) + test( + `j.doe@example.com, + j.doe@example.com. + j.doe@example.com; + j.doe@example.com? + j.doe@example.com!`, + `<p><a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>,<br/> +<a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>.<br/> +<a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>;<br/> +<a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>?<br/> +<a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>!</p>`) + // Test that should *not* be turned into email links test( "\"info@gitea.com\"", |