From 9f2470ff53a911e2ab53fb514f4d302429d2c141 Mon Sep 17 00:00:00 2001 From: kuuuube Date: Sat, 26 Oct 2024 23:08:54 -0400 Subject: [PATCH] Fix UTF16 and UTF32 characters breaking cloze data due to the use of substring --- ext/js/data/anki-note-data-creator.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/js/data/anki-note-data-creator.js b/ext/js/data/anki-note-data-creator.js index 0a401a0c4e..29ff9bc1e3 100644 --- a/ext/js/data/anki-note-data-creator.js +++ b/ext/js/data/anki-note-data-creator.js @@ -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(''), }; }