Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UTF16 and UTF32 characters breaking cloze data due to the use of substring #1533

Merged
merged 3 commits into from
Oct 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions ext/js/data/anki-note-data-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,18 +968,19 @@ function getCloze(dictionaryEntry, context) {
}
if (typeof text !== 'string') { text = ''; }
if (typeof offset !== 'number') { offset = 0; }
const textChars = [...text];

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, textChars.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),
sentence: textChars.join(''),
prefix: textChars.slice(0, offset).join(''),
body: textChars.slice(offset, offset + originalText.length).join(''),
bodyKana: textSegments.join(''),
suffix: text.substring(offset + originalText.length),
suffix: textChars.slice(offset + originalText.length).join(''),
};
}

Expand Down
Loading