mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	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.
This commit is contained in:
		@@ -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)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user