Bug or at least unexpected side effect of replaceAll

Abierto
#176 6 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
javascript
Área
tooling

Línea de trabajo

Start by locating the PureScript strings implementation of replaceAll and its JavaScript replace entry point, then inspect how replacement strings are passed through. Verify the suggested escaping behavior with a regression case involving $' and other dollar-prefixed replacement text; done means replacement strings remain literal.

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

Descripción

In Javascript, the replace function when the first parameter is a Regex, there are special character strings for replacements, e.g. $'.

The problem is that the PureScript replaceAll relies on the JavaScript replace using a Regex with the global flag.

This means that replacement strings are simple string replacements, but instead are interpreted.

Suggested fix:

export const replaceAll = p => r => s => s.replace(new RegExp(p.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"), "g"), r.replace(/\$/g, "$$$$")); // eslint-disable-line no-useless-escape

We're replacing the $ with $$ globally in the replacement string.

Lenguaje dominante
PureScript
Estrellas
57
Forks
76
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

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 purescript/purescript-strings

Todos los issues de purescript/purescript-strings

Issues similares

Más issues de DevTools

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.