kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

`SafeHTML` removes the MathML `<none>` element, which moves scripts in `mmultiscripts`

Open rtibblesbot opened this issue 1 week ago • 2 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Target branch: release-v0.20.x

Observed behavior

SafeHTML removes <none> from MathML. In mmultiscripts, <none> fills an empty script slot, so the script after it moves into that slot.

Input:

<math><mmultiscripts><mi>C</mi><mprescripts/><none/><mn>14</mn></mmultiscripts></math>

DOM that SafeHTML renders:

<math class="safe-html"><mmultiscripts class="safe-html"><mi class="safe-html">C</mi><mprescripts class="safe-html"></mprescripts><mn class="safe-html">14</mn></mmultiscripts></math>

On the MathJax path for browsers without native MathML, 14 renders as a left subscript of C.

DOMPurify 3.4.17 leaves none out of its default MathML tags, and ADD_TAGS adds only object and semantics.

Expected behavior

SafeHTML keeps <none>, so each script stays in its slot.

User-facing consequences

A learner reads a wrong formula. For example, the mass number of an isotope shows where the atomic number belongs.

Steps to reproduce

  1. Render the default export of packages/kolibri-common/components/SafeHTML with the input above as its html prop.
  2. Inspect the rendered mmultiscripts element.

Context

  • Kolibri develop at 758605b764
  • Jest with jsdom
  • #15598 sends MathJax's TeX output through SafeHTML. MathJax writes <none> for \prescript{14}{}{C} and \sideset{^a}{}{\sum}.

Acceptance Criteria

  • [ ] For the input above, the mmultiscripts that SafeHTML renders has <none> between <mprescripts> and <mn>14</mn>.
  • [ ] On the MathJax path, 14 renders as a left superscript of C.
  • [ ] A SafeHTML test covers the input above.

AI usage

Claude Code found this during the self-review of #15598, reproduced it in Jest and drafted this issue.

rtibblesbot avatar Nov 24 '26 10:11 rtibblesbot

Plan: SafeHTML keeps <none> inside mmultiscripts, so each script stays in its slot (#16009).

  • [ ] Keep <none> through sanitisation
  • [ ] Self-review the produced code

Assumptions — the issue did not settle these; say so if one is wrong.

  • A <none> that is not a direct child of mmultiscripts (top level, in msub, in an mrow inside mmultiscripts) falls back to native math on the MathJax path, as a misplaced mprescripts does. Today it is stripped and MathJax renders the expression, so those inputs lose MathJax output on Chromium < 109. If they should keep it, an uponSanitizeElement hook must strip <none> whose parent is not mmultiscripts, and the misplaced-<none> test row inverts.
  • Only none joins the allowlist; if maction, annotation or the mstack family should render too, each needs its own entry and test.
  • A Jest assertion on MathJax's output structure meets the left-superscript criterion; if a rendered capture is required, QA must force the MathJax path in a browser.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 25 '26 01:11 rtibblesbot

Fixed in #16024

rtibbles avatar Nov 25 '26 17:11 rtibbles