mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	Refactor markup rendering to accept general "protocol:" prefix (#29276)
Follow #29024 Major changes: * refactor validLinksPattern to fullURLPattern and add comments, now it accepts "protocol:" prefix * rename `IsLink*` to `IsFullURL*`, and remove unnecessray "mailto:" check * fix some comments (by the way) * rename EmojiShortCodeRegex -> emojiShortCodeRegex (by the way)
This commit is contained in:
		@@ -204,6 +204,15 @@ func TestRender_links(t *testing.T) {
 | 
			
		||||
	test(
 | 
			
		||||
		"magnet:?xt=urn:btih:5dee65101db281ac9c46344cd6b175cdcadabcde&dn=download",
 | 
			
		||||
		`<p><a href="magnet:?xt=urn:btih:5dee65101db281ac9c46344cd6b175cdcadabcde&dn=download" rel="nofollow">magnet:?xt=urn:btih:5dee65101db281ac9c46344cd6b175cdcadabcde&dn=download</a></p>`)
 | 
			
		||||
	test(
 | 
			
		||||
		`[link](https://example.com)`,
 | 
			
		||||
		`<p><a href="https://example.com" rel="nofollow">link</a></p>`)
 | 
			
		||||
	test(
 | 
			
		||||
		`[link](mailto:test@example.com)`,
 | 
			
		||||
		`<p><a href="mailto:test@example.com" rel="nofollow">link</a></p>`)
 | 
			
		||||
	test(
 | 
			
		||||
		`[link](javascript:xss)`,
 | 
			
		||||
		`<p>link</p>`)
 | 
			
		||||
 | 
			
		||||
	// Test that should *not* be turned into URL
 | 
			
		||||
	test(
 | 
			
		||||
@@ -673,3 +682,9 @@ func TestIssue18471(t *testing.T) {
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	assert.Equal(t, "<a href=\"http://domain/org/repo/compare/783b039...da951ce\" class=\"compare\"><code class=\"nohighlight\">783b039...da951ce</code></a>", res.String())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestIsFullURL(t *testing.T) {
 | 
			
		||||
	assert.True(t, markup.IsFullURLString("https://example.com"))
 | 
			
		||||
	assert.True(t, markup.IsFullURLString("mailto:test@example.com"))
 | 
			
		||||
	assert.False(t, markup.IsFullURLString("/foo:bar"))
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user