diff options
author | zeripath <art27@cantab.net> | 2021-09-24 14:29:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-24 14:29:32 +0100 |
commit | 623d2dd411b6a84a01bff3ca8046f1bd01773ffb (patch) | |
tree | b0a006bc910255246756c0105e6d6c3d4c149f04 /modules/markup/orgmode/orgmode_test.go | |
parent | 5842a55b3103d3f09751eb7b3b049415197debad (diff) | |
download | gitea-623d2dd411b6a84a01bff3ca8046f1bd01773ffb.tar.gz gitea-623d2dd411b6a84a01bff3ca8046f1bd01773ffb.zip |
Prevent panic in Org mode HighlightCodeBlock (#17140)
When rendering source in org mode there is a mistake in the highlight code that
causes a panic.
This PR fixes this.
Fix #17139
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/markup/orgmode/orgmode_test.go')
-rw-r--r-- | modules/markup/orgmode/orgmode_test.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/markup/orgmode/orgmode_test.go b/modules/markup/orgmode/orgmode_test.go index da89326e9e..81d0d66a76 100644 --- a/modules/markup/orgmode/orgmode_test.go +++ b/modules/markup/orgmode/orgmode_test.go @@ -57,3 +57,29 @@ func TestRender_Images(t *testing.T) { test("[[file:"+url+"]]", "<p><img src=\""+result+"\" alt=\""+result+"\" title=\""+result+"\" /></p>") } + +func TestRender_Source(t *testing.T) { + setting.AppURL = AppURL + setting.AppSubURL = AppSubURL + + test := func(input, expected string) { + buffer, err := RenderString(&markup.RenderContext{ + URLPrefix: setting.AppSubURL, + }, input) + assert.NoError(t, err) + assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) + } + + test(`#+begin_src go +// HelloWorld prints "Hello World" +func HelloWorld() { + fmt.Println("Hello World") +} +#+end_src +`, `<div class="src src-go"> +<pre><code class="chroma language-go"><span class="c1">// HelloWorld prints "Hello World" +</span><span class="c1"></span><span class="kd">func</span> <span class="nf">HelloWorld</span><span class="p">()</span> <span class="p">{</span> + <span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="s">"Hello World"</span><span class="p">)</span> +<span class="p">}</span></code></pre> +</div>`) +} |