Skip to content

Commit

Permalink
Fix UTF16 and UTF32 characters breaking cloze data due to the use of …
Browse files Browse the repository at this point in the history
…substring
  • Loading branch information
Kuuuube committed Oct 27, 2024
1 parent 019c458 commit 9f2470f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ext/js/data/anki-note-data-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -970,16 +970,16 @@ function getCloze(dictionaryEntry, context) {
if (typeof offset !== 'number') { offset = 0; }

const textSegments = [];
for (const {text: text2, reading: reading2} of distributeFuriganaInflected(term, reading, text.substring(offset, offset + originalText.length))) {
for (const {text: text2, reading: reading2} of distributeFuriganaInflected(term, reading, [...text].slice(offset, offset + originalText.length).join(''))) {
textSegments.push(reading2.length > 0 ? reading2 : text2);
}

return {
sentence: text,
prefix: text.substring(0, offset),
body: text.substring(offset, offset + originalText.length),
prefix: [...text].slice(0, offset).join(''),
body: [...text].slice(offset, offset + originalText.length).join(''),
bodyKana: textSegments.join(''),
suffix: text.substring(offset + originalText.length),
suffix: [...text].slice(offset + originalText.length).join(''),
};
}

Expand Down

0 comments on commit 9f2470f

Please sign in to comment.