@@ -14,6 +14,7 @@ import (
1414 "code.gitea.io/gitea/modules/markup"
1515 "code.gitea.io/gitea/modules/markup/markdown"
1616 "code.gitea.io/gitea/modules/setting"
17+ testModule "code.gitea.io/gitea/modules/test"
1718 "code.gitea.io/gitea/modules/util"
1819
1920 "github.com/stretchr/testify/assert"
@@ -104,7 +105,7 @@ func TestRender_Commits(t *testing.T) {
104105
105106func TestRender_CrossReferences (t * testing.T ) {
106107 setting .AppURL = markup .TestAppURL
107-
108+ defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true )()
108109 test := func (input , expected string ) {
109110 buffer , err := markup .RenderString (& markup.RenderContext {
110111 Ctx : git .DefaultContext ,
@@ -116,9 +117,7 @@ func TestRender_CrossReferences(t *testing.T) {
116117 Metas : localMetas ,
117118 }, input )
118119 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 ))
122121 }
123122
124123 test (
@@ -148,7 +147,7 @@ func TestRender_CrossReferences(t *testing.T) {
148147
149148func TestRender_links (t * testing.T ) {
150149 setting .AppURL = markup .TestAppURL
151-
150+ defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true )()
152151 test := func (input , expected string ) {
153152 buffer , err := markup .RenderString (& markup.RenderContext {
154153 Ctx : git .DefaultContext ,
@@ -158,9 +157,7 @@ func TestRender_links(t *testing.T) {
158157 },
159158 }, input )
160159 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 ))
164161 }
165162
166163 oldCustomURLSchemes := setting .Markdown .CustomURLSchemes
@@ -261,7 +258,7 @@ func TestRender_links(t *testing.T) {
261258
262259func TestRender_email (t * testing.T ) {
263260 setting .AppURL = markup .TestAppURL
264-
261+ defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true )()
265262 test := func (input , expected string ) {
266263 res , err := markup .RenderString (& markup.RenderContext {
267264 Ctx : git .DefaultContext ,
@@ -271,9 +268,7 @@ func TestRender_email(t *testing.T) {
271268 },
272269 }, input )
273270 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 ))
277272 }
278273 // Text that should be turned into email link
279274
@@ -302,10 +297,10 @@ func TestRender_email(t *testing.T) {
302297303298304299305- `<p><a href="mailto:[email protected] " rel="nofollow">[email protected] </a>,<br/> 306- <a href="mailto:[email protected] " rel="nofollow">[email protected] </a>.<br/> 307- <a href="mailto:[email protected] " rel="nofollow">[email protected] </a>;<br/> 308- <a href="mailto:[email protected] " rel="nofollow">[email protected] </a>?<br/> 300+ `<p><a href="mailto:[email protected] " rel="nofollow">[email protected] </a>, 301+ <a href="mailto:[email protected] " rel="nofollow">[email protected] </a>. 302+ <a href="mailto:[email protected] " rel="nofollow">[email protected] </a>; 303+ <a href="mailto:[email protected] " rel="nofollow">[email protected] </a>? 309304<a href="mailto:[email protected] " rel="nofollow">[email protected] </a>!</p>` )
310305
311306 // Test that should *not* be turned into email links
@@ -418,8 +413,8 @@ func TestRender_ShortLinks(t *testing.T) {
418413 Links : markup.Links {
419414 Base : markup .TestRepoURL ,
420415 },
421- Metas : localMetas ,
422- IsWiki : true ,
416+ Metas : localMetas ,
417+ ContentMode : markup . RenderContentAsWiki ,
423418 }, input )
424419 assert .NoError (t , err )
425420 assert .Equal (t , strings .TrimSpace (expectedWiki ), strings .TrimSpace (string (buffer )))
@@ -531,10 +526,10 @@ func TestRender_ShortLinks(t *testing.T) {
531526func TestRender_RelativeMedias (t * testing.T ) {
532527 render := func (input string , isWiki bool , links markup.Links ) string {
533528 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 ) ,
538533 }, input )
539534 assert .NoError (t , err )
540535 return strings .TrimSpace (string (buffer ))
@@ -604,12 +599,7 @@ func Test_ParseClusterFuzz(t *testing.T) {
604599func TestPostProcess_RenderDocument (t * testing.T ) {
605600 setting .AppURL = markup .TestAppURL
606601 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 )()
613603
614604 test := func (input , expected string ) {
615605 var res strings.Builder
@@ -619,12 +609,10 @@ func TestPostProcess_RenderDocument(t *testing.T) {
619609 AbsolutePrefix : true ,
620610 Base : "https://example.com" ,
621611 },
622- Metas : localMetas ,
612+ Metas : map [ string ] string { "user" : "go-gitea" , "repo" : "gitea" } ,
623613 }, strings .NewReader (input ), & res )
624614 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 ()))
628616 }
629617
630618 // Issue index shouldn't be post processing in a document.
0 commit comments