File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,14 @@ export function initMarkupTasklist() {
29
29
30
30
const encoder = new TextEncoder ( ) ;
31
31
const buffer = encoder . encode ( oldContent ) ;
32
+ // Indexes may fall off the ends and return undefined.
33
+ if ( buffer [ position - 1 ] !== '[' . codePointAt ( 0 ) ||
34
+ buffer [ position ] !== ' ' . codePointAt ( 0 ) && buffer [ position ] !== 'x' . codePointAt ( 0 ) ||
35
+ buffer [ position + 1 ] !== ']' . codePointAt ( 0 ) ) {
36
+ // Position is probably wrong. Revert and don't allow change.
37
+ checkbox . checked = ! checkbox . checked ;
38
+ throw new Error ( `Expected position to be space or x and surrounded by brackets, but it's not: position=${ position } ` ) ;
39
+ }
32
40
buffer . set ( encoder . encode ( checkboxCharacter ) , position ) ;
33
41
const newContent = new TextDecoder ( ) . decode ( buffer ) ;
34
42
You can’t perform that action at this time.
0 commit comments