diff options
author | Giteabot <teabot@gitea.io> | 2023-06-13 04:23:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 08:23:21 +0000 |
commit | c207b94e0c99080fe7f43c3049469883fe4dde15 (patch) | |
tree | 14d1b6e5dc2e79a5560baf1dcef0f1126c5f685e /web_src | |
parent | 506c70884a122f92fc722f297f3d775f5d36ba4f (diff) | |
download | gitea-c207b94e0c99080fe7f43c3049469883fe4dde15.tar.gz gitea-c207b94e0c99080fe7f43c3049469883fe4dde15.zip |
Fix task list checkbox toggle to work with YAML front matter (#25184) (#25227)
Backport #25184 by @jtran
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.
Co-authored-by: Jonathan Tran <jon@allspice.io>
Diffstat (limited to 'web_src')
-rw-r--r-- | web_src/js/markup/tasklist.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/web_src/js/markup/tasklist.js b/web_src/js/markup/tasklist.js index 0f03837baa..ad1c6964a7 100644 --- a/web_src/js/markup/tasklist.js +++ b/web_src/js/markup/tasklist.js @@ -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); |