diff options
author | Jonathan Tran <jon@allspice.io> | 2023-06-13 02:44:47 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 14:44:47 +0800 |
commit | f62cd2f4738c1b3cf7c31e8b98702a709bdd4072 (patch) | |
tree | 17dac9b30739851d0a90b848f79f726c05659979 /modules/markup/markdown/markdown_test.go | |
parent | 419804fd4d5cb655a51f245010b8eb1163b26bc2 (diff) | |
download | gitea-f62cd2f4738c1b3cf7c31e8b98702a709bdd4072.tar.gz gitea-f62cd2f4738c1b3cf7c31e8b98702a709bdd4072.zip |
Fix task list checkbox toggle to work with YAML front matter (#25184)
Fixes #25160.
`data-source-position` of checkboxes in a task list was incorrect
whenever there was YAML front matter. This would result in issue content
or PR descriptions getting corrupted with random `x` or space characters
when a user checked or unchecked a task.
Diffstat (limited to 'modules/markup/markdown/markdown_test.go')
-rw-r--r-- | modules/markup/markdown/markdown_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index e81869d7a4..4bd2ca8d41 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -520,3 +520,40 @@ func TestMathBlock(t *testing.T) { } } + +func TestTaskList(t *testing.T) { + testcases := []struct { + testcase string + expected string + }{ + { + // data-source-position should take into account YAML frontmatter. + `--- +foo: bar +--- +- [ ] task 1`, + `<details><summary><i class="icon table"></i></summary><table> +<thead> +<tr> +<th>foo</th> +</tr> +</thead> +<tbody> +<tr> +<td>bar</td> +</tr> +</tbody> +</table> +</details><ul> +<li class="task-list-item"><input type="checkbox" disabled="" data-source-position="19"/>task 1</li> +</ul> +`, + }, + } + + for _, test := range testcases { + res, err := RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, test.testcase) + assert.NoError(t, err, "Unexpected error in testcase: %q", test.testcase) + assert.Equal(t, test.expected, res, "Unexpected result in testcase %q", test.testcase) + } +} |