@@ -14,6 +14,7 @@ import (
14
14
"code.gitea.io/gitea/modules/markup"
15
15
"code.gitea.io/gitea/modules/markup/markdown"
16
16
"code.gitea.io/gitea/modules/setting"
17
+ testModule "code.gitea.io/gitea/modules/test"
17
18
"code.gitea.io/gitea/modules/util"
18
19
19
20
"github.com/stretchr/testify/assert"
@@ -104,7 +105,7 @@ func TestRender_Commits(t *testing.T) {
104
105
105
106
func TestRender_CrossReferences (t * testing.T ) {
106
107
setting .AppURL = markup .TestAppURL
107
-
108
+ defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true )()
108
109
test := func (input , expected string ) {
109
110
buffer , err := markup .RenderString (& markup.RenderContext {
110
111
Ctx : git .DefaultContext ,
@@ -116,9 +117,7 @@ func TestRender_CrossReferences(t *testing.T) {
116
117
Metas : localMetas ,
117
118
}, input )
118
119
assert .NoError (t , err )
119
- actual := strings .TrimSpace (buffer )
120
- actual = strings .ReplaceAll (actual , ` data-markdown-generated-content=""` , "" )
121
- assert .Equal (t , strings .TrimSpace (expected ), actual )
120
+ assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (buffer ))
122
121
}
123
122
124
123
test (
@@ -148,7 +147,7 @@ func TestRender_CrossReferences(t *testing.T) {
148
147
149
148
func TestRender_links (t * testing.T ) {
150
149
setting .AppURL = markup .TestAppURL
151
-
150
+ defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true )()
152
151
test := func (input , expected string ) {
153
152
buffer , err := markup .RenderString (& markup.RenderContext {
154
153
Ctx : git .DefaultContext ,
@@ -158,9 +157,7 @@ func TestRender_links(t *testing.T) {
158
157
},
159
158
}, input )
160
159
assert .NoError (t , err )
161
- actual := strings .TrimSpace (buffer )
162
- actual = strings .ReplaceAll (actual , ` data-markdown-generated-content=""` , "" )
163
- assert .Equal (t , strings .TrimSpace (expected ), actual )
160
+ assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (buffer ))
164
161
}
165
162
166
163
oldCustomURLSchemes := setting .Markdown .CustomURLSchemes
@@ -261,7 +258,7 @@ func TestRender_links(t *testing.T) {
261
258
262
259
func TestRender_email (t * testing.T ) {
263
260
setting .AppURL = markup .TestAppURL
264
-
261
+ defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true )()
265
262
test := func (input , expected string ) {
266
263
res , err := markup .RenderString (& markup.RenderContext {
267
264
Ctx : git .DefaultContext ,
@@ -271,9 +268,7 @@ func TestRender_email(t *testing.T) {
271
268
},
272
269
}, input )
273
270
assert .NoError (t , err )
274
- actual := strings .TrimSpace (res )
275
- actual = strings .ReplaceAll (actual , ` data-markdown-generated-content=""` , "" )
276
- assert .Equal (t , strings .TrimSpace (expected ), actual )
271
+ assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (res ))
277
272
}
278
273
// Text that should be turned into email link
279
274
@@ -302,10 +297,10 @@ func TestRender_email(t *testing.T) {
302
297
j.doe@example.com;
303
298
j.doe@example.com?
304
299
j.doe@example.com!` ,
305
- `<p><a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>,<br/>
306
- <a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>.<br/>
307
- <a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>;<br/>
308
- <a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>?<br/>
300
+ `<p><a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>,
301
+ <a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>.
302
+ <a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>;
303
+ <a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>?
309
304
<a href="mailto:j.doe@example.com" rel="nofollow">j.doe@example.com</a>!</p>` )
310
305
311
306
// Test that should *not* be turned into email links
@@ -418,8 +413,8 @@ func TestRender_ShortLinks(t *testing.T) {
418
413
Links : markup.Links {
419
414
Base : markup .TestRepoURL ,
420
415
},
421
- Metas : localMetas ,
422
- IsWiki : true ,
416
+ Metas : localMetas ,
417
+ ContentMode : markup . RenderContentAsWiki ,
423
418
}, input )
424
419
assert .NoError (t , err )
425
420
assert .Equal (t , strings .TrimSpace (expectedWiki ), strings .TrimSpace (string (buffer )))
@@ -531,10 +526,10 @@ func TestRender_ShortLinks(t *testing.T) {
531
526
func TestRender_RelativeMedias (t * testing.T ) {
532
527
render := func (input string , isWiki bool , links markup.Links ) string {
533
528
buffer , err := markdown .RenderString (& markup.RenderContext {
534
- Ctx : git .DefaultContext ,
535
- Links : links ,
536
- Metas : localMetas ,
537
- IsWiki : isWiki ,
529
+ Ctx : git .DefaultContext ,
530
+ Links : links ,
531
+ Metas : localMetas ,
532
+ ContentMode : util . Iif ( isWiki , markup . RenderContentAsWiki , markup . RenderContentAsComment ) ,
538
533
}, input )
539
534
assert .NoError (t , err )
540
535
return strings .TrimSpace (string (buffer ))
@@ -604,12 +599,7 @@ func Test_ParseClusterFuzz(t *testing.T) {
604
599
func TestPostProcess_RenderDocument (t * testing.T ) {
605
600
setting .AppURL = markup .TestAppURL
606
601
setting .StaticURLPrefix = markup .TestAppURL // can't run standalone
607
-
608
- localMetas := map [string ]string {
609
- "user" : "go-gitea" ,
610
- "repo" : "gitea" ,
611
- "mode" : "document" ,
612
- }
602
+ defer testModule .MockVariableValue (& markup .RenderBehaviorForTesting .DisableInternalAttributes , true )()
613
603
614
604
test := func (input , expected string ) {
615
605
var res strings.Builder
@@ -619,12 +609,10 @@ func TestPostProcess_RenderDocument(t *testing.T) {
619
609
AbsolutePrefix : true ,
620
610
Base : "https://example.com" ,
621
611
},
622
- Metas : localMetas ,
612
+ Metas : map [ string ] string { "user" : "go-gitea" , "repo" : "gitea" } ,
623
613
}, strings .NewReader (input ), & res )
624
614
assert .NoError (t , err )
625
- actual := strings .TrimSpace (res .String ())
626
- actual = strings .ReplaceAll (actual , ` data-markdown-generated-content=""` , "" )
627
- assert .Equal (t , strings .TrimSpace (expected ), actual )
615
+ assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (res .String ()))
628
616
}
629
617
630
618
// Issue index shouldn't be post processing in a document.
0 commit comments