@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/setting"
testModule "code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
@ -104,7 +105,7 @@ func TestRender_Commits(t *testing.T) {
func TestRender_CrossReferences ( t * testing . T ) {
func TestRender_CrossReferences ( t * testing . T ) {
setting . AppURL = markup . TestAppURL
setting . AppURL = markup . TestAppURL
defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true ) ( )
test := func ( input , expected string ) {
test := func ( input , expected string ) {
buffer , err := markup . RenderString ( & markup . RenderContext {
buffer , err := markup . RenderString ( & markup . RenderContext {
Ctx : git . DefaultContext ,
Ctx : git . DefaultContext ,
@ -116,9 +117,7 @@ func TestRender_CrossReferences(t *testing.T) {
Metas : localMetas ,
Metas : localMetas ,
} , input )
} , input )
assert . NoError ( t , err )
assert . NoError ( t , err )
actual := strings . TrimSpace ( buffer )
assert . Equal ( t , strings . TrimSpace ( expected ) , strings . TrimSpace ( buffer ) )
actual = strings . ReplaceAll ( actual , ` data-markdown-generated-content="" ` , "" )
assert . Equal ( t , strings . TrimSpace ( expected ) , actual )
}
}
test (
test (
@ -148,7 +147,7 @@ func TestRender_CrossReferences(t *testing.T) {
func TestRender_links ( t * testing . T ) {
func TestRender_links ( t * testing . T ) {
setting . AppURL = markup . TestAppURL
setting . AppURL = markup . TestAppURL
defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true ) ( )
test := func ( input , expected string ) {
test := func ( input , expected string ) {
buffer , err := markup . RenderString ( & markup . RenderContext {
buffer , err := markup . RenderString ( & markup . RenderContext {
Ctx : git . DefaultContext ,
Ctx : git . DefaultContext ,
@ -158,9 +157,7 @@ func TestRender_links(t *testing.T) {
} ,
} ,
} , input )
} , input )
assert . NoError ( t , err )
assert . NoError ( t , err )
actual := strings . TrimSpace ( buffer )
assert . Equal ( t , strings . TrimSpace ( expected ) , strings . TrimSpace ( buffer ) )
actual = strings . ReplaceAll ( actual , ` data-markdown-generated-content="" ` , "" )
assert . Equal ( t , strings . TrimSpace ( expected ) , actual )
}
}
oldCustomURLSchemes := setting . Markdown . CustomURLSchemes
oldCustomURLSchemes := setting . Markdown . CustomURLSchemes
@ -261,7 +258,7 @@ func TestRender_links(t *testing.T) {
func TestRender_email ( t * testing . T ) {
func TestRender_email ( t * testing . T ) {
setting . AppURL = markup . TestAppURL
setting . AppURL = markup . TestAppURL
defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true ) ( )
test := func ( input , expected string ) {
test := func ( input , expected string ) {
res , err := markup . RenderString ( & markup . RenderContext {
res , err := markup . RenderString ( & markup . RenderContext {
Ctx : git . DefaultContext ,
Ctx : git . DefaultContext ,
@ -271,9 +268,7 @@ func TestRender_email(t *testing.T) {
} ,
} ,
} , input )
} , input )
assert . NoError ( t , err )
assert . NoError ( t , err )
actual := strings . TrimSpace ( res )
assert . Equal ( t , strings . TrimSpace ( expected ) , strings . TrimSpace ( res ) )
actual = strings . ReplaceAll ( actual , ` data-markdown-generated-content="" ` , "" )
assert . Equal ( t , strings . TrimSpace ( expected ) , actual )
}
}
// Text that should be turned into email link
// Text that should be turned into email link
@ -302,10 +297,10 @@ func TestRender_email(t *testing.T) {
j . doe @ example . com ;
j . doe @ example . com ;
j . doe @ example . com ?
j . doe @ example . com ?
j . doe @ example . com ! ` ,
j . doe @ example . com ! ` ,
` < p > < a href = "mailto:j.doe@example.com" rel = "nofollow" > j . doe @ example . com < / a > , < br / >
` < p > < a href = "mailto:j.doe@example.com" rel = "nofollow" > j . doe @ example . com < / a > ,
< a href = "mailto:j.doe@example.com" rel = "nofollow" > j . doe @ example . com < / a > . < br / >
< a href = "mailto:j.doe@example.com" rel = "nofollow" > j . doe @ example . com < / a > .
< a href = "mailto:j.doe@example.com" rel = "nofollow" > j . doe @ example . com < / a > ; < br / >
< a href = "mailto:j.doe@example.com" rel = "nofollow" > j . doe @ example . com < / a > ;
< a href = "mailto:j.doe@example.com" rel = "nofollow" > j . doe @ example . com < / a > ? < br / >
< a href = "mailto:j.doe@example.com" rel = "nofollow" > j . doe @ example . com < / a > ?
< a href = "mailto:j.doe@example.com" rel = "nofollow" > j . doe @ example . com < / a > ! < / p > ` )
< a href = "mailto:j.doe@example.com" rel = "nofollow" > j . doe @ example . com < / a > ! < / p > ` )
// Test that should *not* be turned into email links
// Test that should *not* be turned into email links
@ -418,8 +413,8 @@ func TestRender_ShortLinks(t *testing.T) {
Links : markup . Links {
Links : markup . Links {
Base : markup . TestRepoURL ,
Base : markup . TestRepoURL ,
} ,
} ,
Metas : localMetas ,
Metas : localMetas ,
IsWiki : true ,
ContentMode : markup . RenderContentAsWiki ,
} , input )
} , input )
assert . NoError ( t , err )
assert . NoError ( t , err )
assert . Equal ( t , strings . TrimSpace ( expectedWiki ) , strings . TrimSpace ( string ( buffer ) ) )
assert . Equal ( t , strings . TrimSpace ( expectedWiki ) , strings . TrimSpace ( string ( buffer ) ) )
@ -531,10 +526,10 @@ func TestRender_ShortLinks(t *testing.T) {
func TestRender_RelativeMedias ( t * testing . T ) {
func TestRender_RelativeMedias ( t * testing . T ) {
render := func ( input string , isWiki bool , links markup . Links ) string {
render := func ( input string , isWiki bool , links markup . Links ) string {
buffer , err := markdown . RenderString ( & markup . RenderContext {
buffer , err := markdown . RenderString ( & markup . RenderContext {
Ctx : git . DefaultContext ,
Ctx : git . DefaultContext ,
Links : links ,
Links : links ,
Metas : localMetas ,
Metas : localMetas ,
IsWiki : isWiki ,
ContentMode : util . Iif ( isWiki , markup . RenderContentAsWiki , markup . RenderContentAsComment ) ,
} , input )
} , input )
assert . NoError ( t , err )
assert . NoError ( t , err )
return strings . TrimSpace ( string ( buffer ) )
return strings . TrimSpace ( string ( buffer ) )
@ -604,12 +599,7 @@ func Test_ParseClusterFuzz(t *testing.T) {
func TestPostProcess_RenderDocument ( t * testing . T ) {
func TestPostProcess_RenderDocument ( t * testing . T ) {
setting . AppURL = markup . TestAppURL
setting . AppURL = markup . TestAppURL
setting . StaticURLPrefix = markup . TestAppURL // can't run standalone
setting . StaticURLPrefix = markup . TestAppURL // can't run standalone
defer testModule . MockVariableValue ( & markup . RenderBehaviorForTesting . DisableInternalAttributes , true ) ( )
localMetas := map [ string ] string {
"user" : "go-gitea" ,
"repo" : "gitea" ,
"mode" : "document" ,
}
test := func ( input , expected string ) {
test := func ( input , expected string ) {
var res strings . Builder
var res strings . Builder
@ -619,12 +609,10 @@ func TestPostProcess_RenderDocument(t *testing.T) {
AbsolutePrefix : true ,
AbsolutePrefix : true ,
Base : "https://example.com" ,
Base : "https://example.com" ,
} ,
} ,
Metas : localMetas ,
Metas : map [ string ] string { "user" : "go-gitea" , "repo" : "gitea" } ,
} , strings . NewReader ( input ) , & res )
} , strings . NewReader ( input ) , & res )
assert . NoError ( t , err )
assert . NoError ( t , err )
actual := strings . TrimSpace ( res . String ( ) )
assert . Equal ( t , strings . TrimSpace ( expected ) , strings . TrimSpace ( res . String ( ) ) )
actual = strings . ReplaceAll ( actual , ` data-markdown-generated-content="" ` , "" )
assert . Equal ( t , strings . TrimSpace ( expected ) , actual )
}
}
// Issue index shouldn't be post processing in a document.
// Issue index shouldn't be post processing in a document.