@@ -225,10 +225,10 @@ func TestRender_email(t *testing.T) {
225
225
test := func (input , expected string ) {
226
226
res , err := markup .RenderString (markup .NewTestRenderContext ().WithRelativePath ("a.md" ), input )
227
227
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 )
229
229
}
230
- // Text that should be turned into email link
231
230
231
+ // Text that should be turned into email link
232
232
test (
233
233
234
234
`<p><a href="mailto:[email protected] " rel="nofollow">[email protected] </a></p>` )
@@ -260,28 +260,48 @@ func TestRender_email(t *testing.T) {
260
260
<a href="mailto:[email protected] " rel="nofollow">[email protected] </a>?
261
261
<a href="mailto:[email protected] " rel="nofollow">[email protected] </a>!</p>` )
262
262
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
+
263
269
// Test that should *not* be turned into email links
264
- test (
265
-
266
- `<p>"[email protected] "</p>` )
267
270
test (
268
271
"/home/gitea/mailstore/info@gitea/com" ,
269
272
`<p>/home/gitea/mailstore/info@gitea/com</p>` )
270
273
test (
271
274
"[email protected] :go-gitea/gitea.git" ,
272
275
`<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>` )
273
279
test (
274
280
"gitea@3" ,
275
281
`<p>gitea@3</p>` )
276
282
test (
277
283
278
284
279
- test (
280
-
281
-
282
285
test (
283
286
284
287
288
+
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
+ }
285
305
}
286
306
287
307
func TestRender_emoji (t * testing.T ) {
0 commit comments