Skip to content

Bug or at least unexpected side effect of replaceAll #176

@cscalfani

Description

@cscalfani

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions