Skip to main content

What it flags

A replace or replaceAll call on a string that escapes markup, quote or delimiter characters incompletely:
  • replace with a one-character string pattern or a regex without the g flag, such as html.replace('<', '&lt;') or name.replace('"', '\\"'). Only the first match is escaped.
  • A backslash escape of a delimiter, such as cell.replaceAll('|', '\\|') or s.replace(/"/g, '\\"'), where the receiver does not come from a chain or a local assignment that first escapes backslashes.
The rule resolves the receiver to the built-in string method. The missing-backslash diagnostic skips direct comparison operands and direct inputs to the built-in JSON.stringify when it takes only that input. It also skips return values from a local named replacer whose only uses pass it as the replacer to the built-in JSON.stringify. The check carries earlier escape evidence through a built-in array map only when a direct callback returns its sole parameter unchanged.

How to review or fix

Use replaceAll or a regex with the g flag. Escape backslashes before the delimiter, for example text.replaceAll('\\', '\\\\').replaceAll('|', '\\|'), or use the target format’s own escaping function (JSON.stringify, an HTML escaper, a parameterized query).

Configuration

Set the rule to "off" in loadwise.config.json to drop its findings: