mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 06:38:31 +00:00 
			
		
		
		
	Upgrade to golangci-lint@v1.55.0 (#27756)
https://github.com/golangci/golangci-lint/releases/tag/v1.55.0
This commit is contained in:
		| @@ -14,7 +14,7 @@ import ( | ||||
| 	"code.gitea.io/gitea/modules/emoji" | ||||
| 	"code.gitea.io/gitea/modules/git" | ||||
| 	"code.gitea.io/gitea/modules/log" | ||||
| 	. "code.gitea.io/gitea/modules/markup" | ||||
| 	"code.gitea.io/gitea/modules/markup" | ||||
| 	"code.gitea.io/gitea/modules/markup/markdown" | ||||
| 	"code.gitea.io/gitea/modules/setting" | ||||
| 	"code.gitea.io/gitea/modules/util" | ||||
| @@ -37,12 +37,12 @@ func TestMain(m *testing.M) { | ||||
| } | ||||
|  | ||||
| func TestRender_Commits(t *testing.T) { | ||||
| 	setting.AppURL = TestAppURL | ||||
| 	setting.AppURL = markup.TestAppURL | ||||
| 	test := func(input, expected string) { | ||||
| 		buffer, err := RenderString(&RenderContext{ | ||||
| 		buffer, err := markup.RenderString(&markup.RenderContext{ | ||||
| 			Ctx:          git.DefaultContext, | ||||
| 			RelativePath: ".md", | ||||
| 			URLPrefix:    TestRepoURL, | ||||
| 			URLPrefix:    markup.TestRepoURL, | ||||
| 			Metas:        localMetas, | ||||
| 		}, input) | ||||
| 		assert.NoError(t, err) | ||||
| @@ -50,7 +50,7 @@ func TestRender_Commits(t *testing.T) { | ||||
| 	} | ||||
|  | ||||
| 	sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d" | ||||
| 	repo := TestRepoURL | ||||
| 	repo := markup.TestRepoURL | ||||
| 	commit := util.URLJoin(repo, "commit", sha) | ||||
| 	tree := util.URLJoin(repo, "tree", sha, "src") | ||||
|  | ||||
| @@ -87,10 +87,10 @@ func TestRender_Commits(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestRender_CrossReferences(t *testing.T) { | ||||
| 	setting.AppURL = TestAppURL | ||||
| 	setting.AppURL = markup.TestAppURL | ||||
|  | ||||
| 	test := func(input, expected string) { | ||||
| 		buffer, err := RenderString(&RenderContext{ | ||||
| 		buffer, err := markup.RenderString(&markup.RenderContext{ | ||||
| 			Ctx:          git.DefaultContext, | ||||
| 			RelativePath: "a.md", | ||||
| 			URLPrefix:    setting.AppSubURL, | ||||
| @@ -102,43 +102,43 @@ func TestRender_CrossReferences(t *testing.T) { | ||||
|  | ||||
| 	test( | ||||
| 		"gogits/gogs#12345", | ||||
| 		`<p><a href="`+util.URLJoin(TestAppURL, "gogits", "gogs", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogits/gogs#12345</a></p>`) | ||||
| 		`<p><a href="`+util.URLJoin(markup.TestAppURL, "gogits", "gogs", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogits/gogs#12345</a></p>`) | ||||
| 	test( | ||||
| 		"go-gitea/gitea#12345", | ||||
| 		`<p><a href="`+util.URLJoin(TestAppURL, "go-gitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">go-gitea/gitea#12345</a></p>`) | ||||
| 		`<p><a href="`+util.URLJoin(markup.TestAppURL, "go-gitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">go-gitea/gitea#12345</a></p>`) | ||||
| 	test( | ||||
| 		"/home/gitea/go-gitea/gitea#12345", | ||||
| 		`<p>/home/gitea/go-gitea/gitea#12345</p>`) | ||||
| 	test( | ||||
| 		util.URLJoin(TestAppURL, "gogitea", "gitea", "issues", "12345"), | ||||
| 		`<p><a href="`+util.URLJoin(TestAppURL, "gogitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogitea/gitea#12345</a></p>`) | ||||
| 		util.URLJoin(markup.TestAppURL, "gogitea", "gitea", "issues", "12345"), | ||||
| 		`<p><a href="`+util.URLJoin(markup.TestAppURL, "gogitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogitea/gitea#12345</a></p>`) | ||||
| 	test( | ||||
| 		util.URLJoin(TestAppURL, "go-gitea", "gitea", "issues", "12345"), | ||||
| 		`<p><a href="`+util.URLJoin(TestAppURL, "go-gitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">go-gitea/gitea#12345</a></p>`) | ||||
| 		util.URLJoin(markup.TestAppURL, "go-gitea", "gitea", "issues", "12345"), | ||||
| 		`<p><a href="`+util.URLJoin(markup.TestAppURL, "go-gitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">go-gitea/gitea#12345</a></p>`) | ||||
| 	test( | ||||
| 		util.URLJoin(TestAppURL, "gogitea", "some-repo-name", "issues", "12345"), | ||||
| 		`<p><a href="`+util.URLJoin(TestAppURL, "gogitea", "some-repo-name", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogitea/some-repo-name#12345</a></p>`) | ||||
| 		util.URLJoin(markup.TestAppURL, "gogitea", "some-repo-name", "issues", "12345"), | ||||
| 		`<p><a href="`+util.URLJoin(markup.TestAppURL, "gogitea", "some-repo-name", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogitea/some-repo-name#12345</a></p>`) | ||||
| } | ||||
|  | ||||
| func TestMisc_IsSameDomain(t *testing.T) { | ||||
| 	setting.AppURL = TestAppURL | ||||
| 	setting.AppURL = markup.TestAppURL | ||||
|  | ||||
| 	sha := "b6dd6210eaebc915fd5be5579c58cce4da2e2579" | ||||
| 	commit := util.URLJoin(TestRepoURL, "commit", sha) | ||||
| 	commit := util.URLJoin(markup.TestRepoURL, "commit", sha) | ||||
|  | ||||
| 	assert.True(t, IsSameDomain(commit)) | ||||
| 	assert.False(t, IsSameDomain("http://google.com/ncr")) | ||||
| 	assert.False(t, IsSameDomain("favicon.ico")) | ||||
| 	assert.True(t, markup.IsSameDomain(commit)) | ||||
| 	assert.False(t, markup.IsSameDomain("http://google.com/ncr")) | ||||
| 	assert.False(t, markup.IsSameDomain("favicon.ico")) | ||||
| } | ||||
|  | ||||
| func TestRender_links(t *testing.T) { | ||||
| 	setting.AppURL = TestAppURL | ||||
| 	setting.AppURL = markup.TestAppURL | ||||
|  | ||||
| 	test := func(input, expected string) { | ||||
| 		buffer, err := RenderString(&RenderContext{ | ||||
| 		buffer, err := markup.RenderString(&markup.RenderContext{ | ||||
| 			Ctx:          git.DefaultContext, | ||||
| 			RelativePath: "a.md", | ||||
| 			URLPrefix:    TestRepoURL, | ||||
| 			URLPrefix:    markup.TestRepoURL, | ||||
| 		}, input) | ||||
| 		assert.NoError(t, err) | ||||
| 		assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) | ||||
| @@ -147,8 +147,8 @@ func TestRender_links(t *testing.T) { | ||||
|  | ||||
| 	defaultCustom := setting.Markdown.CustomURLSchemes | ||||
| 	setting.Markdown.CustomURLSchemes = []string{"ftp", "magnet"} | ||||
| 	InitializeSanitizer() | ||||
| 	CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes) | ||||
| 	markup.InitializeSanitizer() | ||||
| 	markup.CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes) | ||||
|  | ||||
| 	test( | ||||
| 		"https://www.example.com", | ||||
| @@ -227,18 +227,18 @@ func TestRender_links(t *testing.T) { | ||||
|  | ||||
| 	// Restore previous settings | ||||
| 	setting.Markdown.CustomURLSchemes = defaultCustom | ||||
| 	InitializeSanitizer() | ||||
| 	CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes) | ||||
| 	markup.InitializeSanitizer() | ||||
| 	markup.CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes) | ||||
| } | ||||
|  | ||||
| func TestRender_email(t *testing.T) { | ||||
| 	setting.AppURL = TestAppURL | ||||
| 	setting.AppURL = markup.TestAppURL | ||||
|  | ||||
| 	test := func(input, expected string) { | ||||
| 		res, err := RenderString(&RenderContext{ | ||||
| 		res, err := markup.RenderString(&markup.RenderContext{ | ||||
| 			Ctx:          git.DefaultContext, | ||||
| 			RelativePath: "a.md", | ||||
| 			URLPrefix:    TestRepoURL, | ||||
| 			URLPrefix:    markup.TestRepoURL, | ||||
| 		}, input) | ||||
| 		assert.NoError(t, err) | ||||
| 		assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res)) | ||||
| @@ -289,15 +289,15 @@ func TestRender_email(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestRender_emoji(t *testing.T) { | ||||
| 	setting.AppURL = TestAppURL | ||||
| 	setting.StaticURLPrefix = TestAppURL | ||||
| 	setting.AppURL = markup.TestAppURL | ||||
| 	setting.StaticURLPrefix = markup.TestAppURL | ||||
|  | ||||
| 	test := func(input, expected string) { | ||||
| 		expected = strings.ReplaceAll(expected, "&", "&") | ||||
| 		buffer, err := RenderString(&RenderContext{ | ||||
| 		buffer, err := markup.RenderString(&markup.RenderContext{ | ||||
| 			Ctx:          git.DefaultContext, | ||||
| 			RelativePath: "a.md", | ||||
| 			URLPrefix:    TestRepoURL, | ||||
| 			URLPrefix:    markup.TestRepoURL, | ||||
| 		}, input) | ||||
| 		assert.NoError(t, err) | ||||
| 		assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) | ||||
| @@ -354,19 +354,19 @@ func TestRender_emoji(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestRender_ShortLinks(t *testing.T) { | ||||
| 	setting.AppURL = TestAppURL | ||||
| 	tree := util.URLJoin(TestRepoURL, "src", "master") | ||||
| 	setting.AppURL = markup.TestAppURL | ||||
| 	tree := util.URLJoin(markup.TestRepoURL, "src", "master") | ||||
|  | ||||
| 	test := func(input, expected, expectedWiki string) { | ||||
| 		buffer, err := markdown.RenderString(&RenderContext{ | ||||
| 		buffer, err := markdown.RenderString(&markup.RenderContext{ | ||||
| 			Ctx:       git.DefaultContext, | ||||
| 			URLPrefix: tree, | ||||
| 		}, input) | ||||
| 		assert.NoError(t, err) | ||||
| 		assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) | ||||
| 		buffer, err = markdown.RenderString(&RenderContext{ | ||||
| 		buffer, err = markdown.RenderString(&markup.RenderContext{ | ||||
| 			Ctx:       git.DefaultContext, | ||||
| 			URLPrefix: TestRepoURL, | ||||
| 			URLPrefix: markup.TestRepoURL, | ||||
| 			Metas:     localMetas, | ||||
| 			IsWiki:    true, | ||||
| 		}, input) | ||||
| @@ -374,7 +374,7 @@ func TestRender_ShortLinks(t *testing.T) { | ||||
| 		assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer)) | ||||
| 	} | ||||
|  | ||||
| 	rawtree := util.URLJoin(TestRepoURL, "raw", "master") | ||||
| 	rawtree := util.URLJoin(markup.TestRepoURL, "raw", "master") | ||||
| 	url := util.URLJoin(tree, "Link") | ||||
| 	otherURL := util.URLJoin(tree, "Other-Link") | ||||
| 	encodedURL := util.URLJoin(tree, "Link%3F") | ||||
| @@ -382,13 +382,13 @@ func TestRender_ShortLinks(t *testing.T) { | ||||
| 	otherImgurl := util.URLJoin(rawtree, "Link+Other.jpg") | ||||
| 	encodedImgurl := util.URLJoin(rawtree, "Link+%23.jpg") | ||||
| 	notencodedImgurl := util.URLJoin(rawtree, "some", "path", "Link+#.jpg") | ||||
| 	urlWiki := util.URLJoin(TestRepoURL, "wiki", "Link") | ||||
| 	otherURLWiki := util.URLJoin(TestRepoURL, "wiki", "Other-Link") | ||||
| 	encodedURLWiki := util.URLJoin(TestRepoURL, "wiki", "Link%3F") | ||||
| 	imgurlWiki := util.URLJoin(TestRepoURL, "wiki", "raw", "Link.jpg") | ||||
| 	otherImgurlWiki := util.URLJoin(TestRepoURL, "wiki", "raw", "Link+Other.jpg") | ||||
| 	encodedImgurlWiki := util.URLJoin(TestRepoURL, "wiki", "raw", "Link+%23.jpg") | ||||
| 	notencodedImgurlWiki := util.URLJoin(TestRepoURL, "wiki", "raw", "some", "path", "Link+#.jpg") | ||||
| 	urlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "Link") | ||||
| 	otherURLWiki := util.URLJoin(markup.TestRepoURL, "wiki", "Other-Link") | ||||
| 	encodedURLWiki := util.URLJoin(markup.TestRepoURL, "wiki", "Link%3F") | ||||
| 	imgurlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw", "Link.jpg") | ||||
| 	otherImgurlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw", "Link+Other.jpg") | ||||
| 	encodedImgurlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw", "Link+%23.jpg") | ||||
| 	notencodedImgurlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw", "some", "path", "Link+#.jpg") | ||||
| 	favicon := "http://google.com/favicon.ico" | ||||
|  | ||||
| 	test( | ||||
| @@ -462,20 +462,20 @@ func TestRender_ShortLinks(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestRender_RelativeImages(t *testing.T) { | ||||
| 	setting.AppURL = TestAppURL | ||||
| 	tree := util.URLJoin(TestRepoURL, "src", "master") | ||||
| 	setting.AppURL = markup.TestAppURL | ||||
| 	tree := util.URLJoin(markup.TestRepoURL, "src", "master") | ||||
|  | ||||
| 	test := func(input, expected, expectedWiki string) { | ||||
| 		buffer, err := markdown.RenderString(&RenderContext{ | ||||
| 		buffer, err := markdown.RenderString(&markup.RenderContext{ | ||||
| 			Ctx:       git.DefaultContext, | ||||
| 			URLPrefix: tree, | ||||
| 			Metas:     localMetas, | ||||
| 		}, input) | ||||
| 		assert.NoError(t, err) | ||||
| 		assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) | ||||
| 		buffer, err = markdown.RenderString(&RenderContext{ | ||||
| 		buffer, err = markdown.RenderString(&markup.RenderContext{ | ||||
| 			Ctx:       git.DefaultContext, | ||||
| 			URLPrefix: TestRepoURL, | ||||
| 			URLPrefix: markup.TestRepoURL, | ||||
| 			Metas:     localMetas, | ||||
| 			IsWiki:    true, | ||||
| 		}, input) | ||||
| @@ -483,8 +483,8 @@ func TestRender_RelativeImages(t *testing.T) { | ||||
| 		assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer)) | ||||
| 	} | ||||
|  | ||||
| 	rawwiki := util.URLJoin(TestRepoURL, "wiki", "raw") | ||||
| 	mediatree := util.URLJoin(TestRepoURL, "media", "master") | ||||
| 	rawwiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw") | ||||
| 	mediatree := util.URLJoin(markup.TestRepoURL, "media", "master") | ||||
|  | ||||
| 	test( | ||||
| 		`<img src="Link">`, | ||||
| @@ -498,7 +498,7 @@ func TestRender_RelativeImages(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func Test_ParseClusterFuzz(t *testing.T) { | ||||
| 	setting.AppURL = TestAppURL | ||||
| 	setting.AppURL = markup.TestAppURL | ||||
|  | ||||
| 	localMetas := map[string]string{ | ||||
| 		"user": "go-gitea", | ||||
| @@ -508,7 +508,7 @@ func Test_ParseClusterFuzz(t *testing.T) { | ||||
| 	data := "<A><maTH><tr><MN><bodY ÿ><temPlate></template><tH><tr></A><tH><d<bodY " | ||||
|  | ||||
| 	var res strings.Builder | ||||
| 	err := PostProcess(&RenderContext{ | ||||
| 	err := markup.PostProcess(&markup.RenderContext{ | ||||
| 		Ctx:       git.DefaultContext, | ||||
| 		URLPrefix: "https://example.com", | ||||
| 		Metas:     localMetas, | ||||
| @@ -519,7 +519,7 @@ func Test_ParseClusterFuzz(t *testing.T) { | ||||
| 	data = "<!DOCTYPE html>\n<A><maTH><tr><MN><bodY ÿ><temPlate></template><tH><tr></A><tH><d<bodY " | ||||
|  | ||||
| 	res.Reset() | ||||
| 	err = PostProcess(&RenderContext{ | ||||
| 	err = markup.PostProcess(&markup.RenderContext{ | ||||
| 		Ctx:       git.DefaultContext, | ||||
| 		URLPrefix: "https://example.com", | ||||
| 		Metas:     localMetas, | ||||
| @@ -530,7 +530,7 @@ func Test_ParseClusterFuzz(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestPostProcess_RenderDocument(t *testing.T) { | ||||
| 	setting.AppURL = TestAppURL | ||||
| 	setting.AppURL = markup.TestAppURL | ||||
|  | ||||
| 	localMetas := map[string]string{ | ||||
| 		"user": "go-gitea", | ||||
| @@ -540,7 +540,7 @@ func TestPostProcess_RenderDocument(t *testing.T) { | ||||
|  | ||||
| 	test := func(input, expected string) { | ||||
| 		var res strings.Builder | ||||
| 		err := PostProcess(&RenderContext{ | ||||
| 		err := markup.PostProcess(&markup.RenderContext{ | ||||
| 			Ctx:       git.DefaultContext, | ||||
| 			URLPrefix: "https://example.com", | ||||
| 			Metas:     localMetas, | ||||
| @@ -566,7 +566,7 @@ func TestPostProcess_RenderDocument(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestIssue16020(t *testing.T) { | ||||
| 	setting.AppURL = TestAppURL | ||||
| 	setting.AppURL = markup.TestAppURL | ||||
|  | ||||
| 	localMetas := map[string]string{ | ||||
| 		"user": "go-gitea", | ||||
| @@ -576,7 +576,7 @@ func TestIssue16020(t *testing.T) { | ||||
| 	data := `<img src="data:image/png;base64,i//V"/>` | ||||
|  | ||||
| 	var res strings.Builder | ||||
| 	err := PostProcess(&RenderContext{ | ||||
| 	err := markup.PostProcess(&markup.RenderContext{ | ||||
| 		Ctx:       git.DefaultContext, | ||||
| 		URLPrefix: "https://example.com", | ||||
| 		Metas:     localMetas, | ||||
| @@ -593,7 +593,7 @@ func BenchmarkEmojiPostprocess(b *testing.B) { | ||||
| 	b.ResetTimer() | ||||
| 	for i := 0; i < b.N; i++ { | ||||
| 		var res strings.Builder | ||||
| 		err := PostProcess(&RenderContext{ | ||||
| 		err := markup.PostProcess(&markup.RenderContext{ | ||||
| 			Ctx:       git.DefaultContext, | ||||
| 			URLPrefix: "https://example.com", | ||||
| 			Metas:     localMetas, | ||||
| @@ -604,7 +604,7 @@ func BenchmarkEmojiPostprocess(b *testing.B) { | ||||
|  | ||||
| func TestFuzz(t *testing.T) { | ||||
| 	s := "t/l/issues/8#/../../a" | ||||
| 	renderContext := RenderContext{ | ||||
| 	renderContext := markup.RenderContext{ | ||||
| 		Ctx:       git.DefaultContext, | ||||
| 		URLPrefix: "https://example.com/go-gitea/gitea", | ||||
| 		Metas: map[string]string{ | ||||
| @@ -613,7 +613,7 @@ func TestFuzz(t *testing.T) { | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	err := PostProcess(&renderContext, strings.NewReader(s), io.Discard) | ||||
| 	err := markup.PostProcess(&renderContext, strings.NewReader(s), io.Discard) | ||||
|  | ||||
| 	assert.NoError(t, err) | ||||
| } | ||||
| @@ -622,7 +622,7 @@ func TestIssue18471(t *testing.T) { | ||||
| 	data := `http://domain/org/repo/compare/783b039...da951ce` | ||||
|  | ||||
| 	var res strings.Builder | ||||
| 	err := PostProcess(&RenderContext{ | ||||
| 	err := markup.PostProcess(&markup.RenderContext{ | ||||
| 		Ctx:       git.DefaultContext, | ||||
| 		URLPrefix: "https://example.com", | ||||
| 		Metas:     localMetas, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user