mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 14:37:28 -04:00 
			
		
		
		
	* Fix #33972 * Use consistent path resolving for links and medias. * No need to make the markup renders to resolve the paths, instead, the paths are all correctly resolved in the "post process" step. * Fix #33274 * Since 1.23, all paths starting with "/" are relative to current render context (for example: the current repo branch) * Introduce `/:root/path-relative-to-root`, then the path will be rendered as relative to "ROOT_URL"
		
			
				
	
	
		
			73 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2024 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package markup_test
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"html/template"
 | |
| 	"strings"
 | |
| 	"testing"
 | |
| 
 | |
| 	"code.gitea.io/gitea/modules/htmlutil"
 | |
| 	"code.gitea.io/gitea/modules/markup"
 | |
| 	"code.gitea.io/gitea/modules/markup/markdown"
 | |
| 	testModule "code.gitea.io/gitea/modules/test"
 | |
| 
 | |
| 	"github.com/stretchr/testify/assert"
 | |
| 	"github.com/stretchr/testify/require"
 | |
| )
 | |
| 
 | |
| func TestRender_IssueList(t *testing.T) {
 | |
| 	defer testModule.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
 | |
| 	markup.Init(&markup.RenderHelperFuncs{
 | |
| 		RenderRepoIssueIconTitle: func(ctx context.Context, opts markup.RenderIssueIconTitleOptions) (template.HTML, error) {
 | |
| 			return htmlutil.HTMLFormat("<div>issue #%d</div>", opts.IssueIndex), nil
 | |
| 		},
 | |
| 	})
 | |
| 
 | |
| 	test := func(input, expected string) {
 | |
| 		rctx := markup.NewTestRenderContext(markup.TestAppURL, map[string]string{
 | |
| 			"user": "test-user", "repo": "test-repo",
 | |
| 			"markupAllowShortIssuePattern": "true",
 | |
| 		})
 | |
| 		out, err := markdown.RenderString(rctx, input)
 | |
| 		require.NoError(t, err)
 | |
| 		assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
 | |
| 	}
 | |
| 
 | |
| 	t.Run("NormalIssueRef", func(t *testing.T) {
 | |
| 		test(
 | |
| 			"#12345",
 | |
| 			`<p><a href="/test-user/test-repo/issues/12345" class="ref-issue" rel="nofollow">#12345</a></p>`,
 | |
| 		)
 | |
| 	})
 | |
| 
 | |
| 	t.Run("ListIssueRef", func(t *testing.T) {
 | |
| 		test(
 | |
| 			"* #12345",
 | |
| 			`<ul>
 | |
| <li><div>issue #12345</div></li>
 | |
| </ul>`,
 | |
| 		)
 | |
| 	})
 | |
| 
 | |
| 	t.Run("ListIssueRefNormal", func(t *testing.T) {
 | |
| 		test(
 | |
| 			"* foo #12345 bar",
 | |
| 			`<ul>
 | |
| <li>foo <a href="/test-user/test-repo/issues/12345" class="ref-issue" rel="nofollow">#12345</a> bar</li>
 | |
| </ul>`,
 | |
| 		)
 | |
| 	})
 | |
| 
 | |
| 	t.Run("ListTodoIssueRef", func(t *testing.T) {
 | |
| 		test(
 | |
| 			"* [ ] #12345",
 | |
| 			`<ul>
 | |
| <li class="task-list-item"><input type="checkbox" disabled="" data-source-position="2"/><div>issue #12345</div></li>
 | |
| </ul>`,
 | |
| 		)
 | |
| 	})
 | |
| }
 |