normalizeNumerals misreads Unicode mathematical digits
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Target branch: develop
Observed behavior
normalizeNumerals gives the wrong value for Unicode mathematical digits that do not start their run:
normalizeNumerals('𝟙')(U+1D7D9, double-struck 1) returns'11'.normalizeNumerals('𝟣')(U+1D7E3, sans-serif 1) returns'21'.- Bold digits (U+1D7CE–U+1D7D7) read correctly.
U+1D7CE–U+1D7FF is one unbroken 50-character run of \p{Nd} digits. The function walks back to the start of the run and subtracts, so its comment's "at most 9 steps" does not hold. Every \p{Nd} run is a multiple of 10 long.
User-facing consequences
A learner who pastes such digits into a Numeric TextEntryInteraction in qti_viewer has their answer read as a different number.
Steps to reproduce
- In a jest test or browser console, import
normalizeNumeralsfromkolibri-common/utils/numeralNormalization. - Call
normalizeNumerals('𝟙').
Acceptance Criteria
- [ ]
normalizeNumeralsreturns'1'for𝟙(U+1D7D9) and𝟣(U+1D7E3), and'0'–'9'for every digit in U+1D7CE–U+1D7FF. - [ ]
numeralNormalization.spec.jscovers a digit from the middle of the mathematical run.
AI usage
Claude Code found this while reviewing Studio's vendored copy in learningequality/studio#6282, which fixes the same bug, and drafted this issue.
Plan: normalizeNumerals reads every \p{Nd} digit as its value 0–9, including digits inside runs longer than 10.
- [ ] Read digits from runs longer than 10
- [ ] Self-review the produced code
Written by rtibblesbot, an LLM-based coding agent.