@@ -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 (
233233 "info@gitea.com" ,
234234 `<p><a href="mailto:info@gitea.com" rel="nofollow">info@gitea.com</a></p>` )
@@ -260,28 +260,48 @@ func TestRender_email(t *testing.T) {
260260<a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>?
261261<a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>!</p>` )
262262
263+ // match GitHub behavior
264+ test ("email@domain@domain.com" , `<p>email@<a href="mailto:domain@domain.com" rel="nofollow">domain@domain.com</a></p>` )
265+
266+ // match GitHub behavior
267+ test (`"info@gitea.com"` , `<p>"<a href="mailto:info@gitea.com" rel="nofollow">info@gitea.com</a>"</p>` )
268+
263269 // Test that should *not* be turned into email links
264- test (
265- "\" info@gitea.com\" " ,
266- `<p>"info@gitea.com"</p>` )
267270 test (
268271 "/home/gitea/mailstore/info@gitea/com" ,
269272 `<p>/home/gitea/mailstore/info@gitea/com</p>` )
270273 test (
271274 "git@try.gitea.io:go-gitea/gitea.git" ,
272275 `<p>git@try.gitea.io:go-gitea/gitea.git</p>` )
276+ test (
277+ "https://foo:bar@gitea.io" ,
278+ `<p><a href="https://foo:bar@gitea.io" rel="nofollow">https://foo:bar@gitea.io</a></p>` )
273279 test (
274280 "gitea@3" ,
275281 `<p>gitea@3</p>` )
276282 test (
277283 "gitea@gmail.c" ,
278284 `<p>gitea@gmail.c</p>` )
279- test (
280- "email@domain@domain.com" ,
281- `<p>email@domain@domain.com</p>` )
282285 test (
283286 "email@domain..com" ,
284287 `<p>email@domain..com</p>` )
288+
289+ cases := []struct {
290+ input , expected string
291+ }{
292+ // match GitHub behavior
293+ {"?a@d.zz" , `<p>?<a href="mailto:a@d.zz" rel="nofollow">a@d.zz</a></p>` },
294+ {"*a@d.zz" , `<p>*<a href="mailto:a@d.zz" rel="nofollow">a@d.zz</a></p>` },
295+ {"~a@d.zz" , `<p>~<a href="mailto:a@d.zz" rel="nofollow">a@d.zz</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*a@d.zz" , `<p><a href="mailto:a*a@d.zz" rel="nofollow">a*a@d.zz</a></p>` },
300+ {"a~a@d.zz" , `<p><a href="mailto:a~a@d.zz" rel="nofollow">a~a@d.zz</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