Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

diffCleanupSemantic(Lossless) can run into an infinite loop

Abierto
#7 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
74/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
javascript, typescript
Área
tooling

Línea de trabajo

Ejecuta primero la reproducción proporcionada, luego inspecciona la lógica citada en src/diff.ts alrededor de diffCleanupSemantic y compárala con la implementación de Java enlazada. Usa la entrada diffFromDelta preparada para verificar que el bloqueo ha desaparecido y confirma el comportamiento documentado para entradas no válidas, idealmente con cobertura de regresión.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Describe the bug

For a specifically crafted input, diffFromDelta would produce a delta that cause diffCleanupSemantic and diffCleanupSemanticLossless to hang (infinite loop).

The documentation for diffFromDelta says that it would throw on invalid input, but it's not doing that for this case. Or this could be an issue with diffCleanupSemantic and diffCleanupSemanticLossless where they are mishandling specific diffs.

This is happening due to the empty edit/equality tuples. Reproducible on the latest v2.0.1.

Reproduction:

import { diffCleanupSemantic, diffFromDelta } from 'diff-match-patch-es'

const diffs = diffFromDelta('ac', '=1\t-0\t=0\t+b\t=1')

console.log('diff:', JSON.stringify(diffs))
diffCleanupSemantic(diffs)

Potential fix (unverified):

The original Java version has some extra check:

https://github.com/google/diff-match-patch/blob/62f2e689f498f9c92dbc588c58750addec9b1654/java/src/name/fraser/neil/plaintext/diff_match_patch.java#L938-L939

        while (edit.length() != 0 && equality2.length() != 0
            && edit.charAt(0) == equality2.charAt(0)) {

But missing from the JS (and TS) version:

https://github.com/antfu/diff-match-patch-es/blob/4f35fb7fd57df68d69068cdee0780bb779f5497f/src/diff.ts#L880

Reproduction

https://github.com/aforemendude/bugs-reproduction/tree/main/diff-match-patch-es-delta-inf-loop

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.39 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!)
Lenguaje dominante
TypeScript
Estrellas
200
Forks
6
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de antfu/diff-match-patch-es

Todos los issues de antfu/diff-match-patch-es

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.