@@ -225,10 +225,10 @@ func TestRender_email(t *testing.T) {
225225 test := func (input , expected string ) {
226226 res , err := markup .RenderString (markup .NewTestRenderContext ().WithRelativePath ("a.md" ), input )
227227 assert .NoError (t , err )
228- assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (res ))
228+ assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (res ), "input: %s" , input )
229229 }
230- // Text that should be turned into email link
231230
231+ // Text that should be turned into email link
232232 test (
233233234234 `<p><a href="mailto:[email protected] " rel="nofollow">[email protected] </a></p>` )
@@ -260,28 +260,48 @@ func TestRender_email(t *testing.T) {
260260<a href="mailto:[email protected] " rel="nofollow">[email protected] </a>? 261261<a href="mailto:[email protected] " rel="nofollow">[email protected] </a>!</p>` )
262262
263+ // match GitHub behavior
264+ test (
"email@[email protected] " ,
`<p>email@<a href="mailto:[email protected] " rel="nofollow">[email protected] </a></p>` )
265+
266+ // match GitHub behavior
267+ test (
`"[email protected] "` ,
`<p>"<a href="mailto:[email protected] " rel="nofollow">[email protected] </a>"</p>` )
268+
263269 // Test that should *not* be turned into email links
264- test (
265- 266- `<p>"[email protected] "</p>` )
267270 test (
268271 "/home/gitea/mailstore/info@gitea/com" ,
269272 `<p>/home/gitea/mailstore/info@gitea/com</p>` )
270273 test (
271274 "[email protected] :go-gitea/gitea.git" ,
272275 `<p>[email protected] :go-gitea/gitea.git</p>` )
276+ test (
277+ 278+ `<p><a href="https://foo:[email protected] " rel="nofollow">https://foo:[email protected] </a></p>` )
273279 test (
274280 "gitea@3" ,
275281 `<p>gitea@3</p>` )
276282 test (
277283278284279- test (
280- 281- 282285 test (
283286284287288+
289+ cases := []struct {
290+ input , expected string
291+ }{
292+ // match GitHub behavior
293+ {
"[email protected] " ,
`<p>?<a href="mailto:[email protected] " rel="nofollow">[email protected] </a></p>` },
294+ {
"*[email protected] " ,
`<p>*<a href="mailto:[email protected] " rel="nofollow">[email protected] </a></p>` },
295+ {
"[email protected] " ,
`<p>~<a href="mailto:[email protected] " rel="nofollow">[email protected] </a></p>` },
296+
297+ // the following cases don't match GitHub behavior, but they are valid email addresses ...
298+ // maybe we should reduce the candidate characters for the "name" part in the future
299+ {
"a*[email protected] " ,
`<p><a href="mailto:a*[email protected] " rel="nofollow">a*[email protected] </a></p>` },
300+ {
"[email protected] " ,
`<p><a href="mailto:[email protected] " rel="nofollow">[email protected] </a></p>` },
301+ }
302+ for _ , c := range cases {
303+ test (c .input , c .expected )
304+ }
285305}
286306
287307func TestRender_emoji (t * testing.T ) {
0 commit comments