Annotation save fails when the quote prefix or suffix splits a surrogate pair (e.g., next to MathJax 4 math)

Aperta
#7,586 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
frontend

Direzione di ricerca

The payload does not name the file, so start by finding where the text-quote selector's 32-code-unit prefix and suffix are cut, then reproduce with the HTML snippet in the issue (highlight consectetur, save). The cut must not leave a lone surrogate, either by moving the boundary one code unit or by slicing on code points. Done when the reproduction saves and a test covers a boundary that falls inside a non-BMP character.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Saving an annotation fails with "Saving annotation failed" when the text-quote selector's prefix or suffix boundary falls in the middle of a non-BMP character, such as a character from the Mathematical Alphanumeric Symbols block.

This happens a lot on pages that use MathJax 4 with CHTML output. MathJax 4 writes each glyph as a DOM text node, and it maps italic variables to Unicode math-italic code points; for example, x becomes 𝑥 (U+1D465). In JavaScript these characters are stored as two code units (a surrogate pair). The prefix and suffix are cut at a fixed 32 code units, so if the cut falls between the two halves, the selector ends up with a lone surrogate. I believe the save fails at that point.

Steps to reproduce

  1. Serve this page and open it with the Hypothesis client active:

    <!doctype html>
    <html><head>
    <script async src="https://hypothes.is/embed.js"></script>
    </head><body>
    <p>Lorem ipsum consectetur. Lorem ipsum dolor sit ametus &#x1D465; elit.</p>
    </body></html>
    

    (You don't need MathJax to reproduce this; the &#x1D465; stands in for its output.)

  2. Highlight consectetur and click Annotate.

  3. Enter text and save.

Expected: The annotation saves.

Actual: "Saving annotation failed." The text after the highlight, . Lorem ipsum dolor sit ametus (31 code units), is followed by the two-unit 𝑥, so the 32-unit suffix ends with the lone high surrogate \uD835.

Highlighting the first Lorem ipsum instead saves normally, because its 32-unit suffix ends well before the 𝑥.

Suggested fix

When cutting prefix/suffix, don't split a surrogate pair. Move the boundary by one code unit when it would leave half of a non-BMP character, or cut by code point rather than by code unit.

Impact

On math-heavy pages that use MathJax 4 (e.g., textbooks), many highlights near inline math fail: any selection whose start or end is within 32 code units of an italic variable can be affected.

Lingua principale
Mustache
Stelle
743
Fork
227
Merge medio
6m
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di hypothesis/client

Tutte le issue di hypothesis/client

Issue simili

Altre issue su Web Dev

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.