diffToDelta and patchToText can throw if diff split surrogate-pair
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 70/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- javascript, typescript
- Ambito
- tooling
Direzione di ricerca
Inizia dagli entry point diff, diffToDelta, patch e patchToText mostrati nella riproduzione, quindi esegui l’esempio di coppia surrogata fornito. Traccia il percorso dei caratteri separati fino al passaggio di codifica URI; il lavoro è completato quando l’esempio termina senza URIError e conserva il testo diff e patch previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
The current diff implementation operates on UTF-16 characters directly, which can cause it to split surrogate-pairs. When this happens, diffToDelta and patchToText can throw URIError.
Reproducible on the latest v2.0.1.
Reproduction:
import { diff, diffToDelta, patch, patchToText } from 'diff-match-patch-es'
const oldText = '😀'
const newText = '😃'
const diffs = diff(oldText, newText)
console.log('diff:', JSON.stringify(diffs))
for (const [label, reproduce] of [
['diffToDelta', () => diffToDelta(diffs)],
['patchToText', () => patchToText(patch(oldText, newText))],
]) {
try {
console.log(`${label}:`, reproduce())
} catch (error) {
console.log(`${label}:`, `${error.name}: ${error.message}`)
}
}
Output:
diff: [[0,"\ud83d"],[-1,"\ude00"],[1,"\ude03"]]
diffToDelta: URIError: URI malformed
patchToText: URIError: URI malformed
Reproduction
https://github.com/aforemendude/bugs-reproduction/tree/main/diff-match-patch-es-urierror
System Info
System:
OS: Linux 7.0 Ubuntu 24.04.4 LTS 24.04.4 LTS (Noble Numbat)
CPU: (4) x64 Intel(R) N95
Memory: 12.10 GB / 15.40 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 24.18.0 - /usr/local/nodejs/bin/node
npm: 11.16.0 - /usr/local/nodejs/bin/npm
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
- The provided reproduction is a minimal reproducible of the bug.
Contributions
- I am willing to submit a PR to fix this issue
- I am willing to submit a PR with failing tests (actually just go ahead and do it, thanks!)
- Lingua principale
- TypeScript
- Stelle
- 200
- Fork
- 6
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di antfu/diff-match-patch-es
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 74/100
Tutte le issue di antfu/diff-match-patch-es
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
rohitg00/agentmemory#1428 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
boxlite-ai/boxlite#1729 ·
I maintainer di solito rispondono entro 1 giorno
-
detectors enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
SM260845/readme-gen#1 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
angular/angularfire#3774 ·
I maintainer di solito rispondono entro 2 giorni