diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-02-21 18:08:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-21 10:08:08 +0000 |
commit | 6130522aa86316c7d87e130cc8c440fd06920928 (patch) | |
tree | e3b27d8a797977fe431f03f0d70ce168edbad10b /modules/markup/html_test.go | |
parent | 4e536edaead97d61a64508db0e93cf781a889472 (diff) | |
download | gitea-6130522aa86316c7d87e130cc8c440fd06920928.tar.gz gitea-6130522aa86316c7d87e130cc8c440fd06920928.zip |
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)
Diffstat (limited to 'modules/markup/html_test.go')
-rw-r--r-- | modules/markup/html_test.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 89ecfc036b..cb29431d4b 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -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")) +} |