mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08: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:
		@@ -29,6 +29,14 @@ export function initMarkupTasklist() {
 | 
			
		||||
 | 
			
		||||
        const encoder = new TextEncoder();
 | 
			
		||||
        const buffer = encoder.encode(oldContent);
 | 
			
		||||
        // Indexes may fall off the ends and return undefined.
 | 
			
		||||
        if (buffer[position - 1] !== '['.codePointAt(0) ||
 | 
			
		||||
          buffer[position] !== ' '.codePointAt(0) && buffer[position] !== 'x'.codePointAt(0) ||
 | 
			
		||||
          buffer[position + 1] !== ']'.codePointAt(0)) {
 | 
			
		||||
          // Position is probably wrong.  Revert and don't allow change.
 | 
			
		||||
          checkbox.checked = !checkbox.checked;
 | 
			
		||||
          throw new Error(`Expected position to be space or x and surrounded by brackets, but it's not: position=${position}`);
 | 
			
		||||
        }
 | 
			
		||||
        buffer.set(encoder.encode(checkboxCharacter), position);
 | 
			
		||||
        const newContent = new TextDecoder().decode(buffer);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user