Skip to content

🐛 Bug: escapeSpecialCharacters in 1.7.2 corrupts interpolated expressions containing backslash sequences #109

@audun-cobrief

Description

@audun-cobrief

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Expected

Interpolated expressions should pass through unmodified. A template like:

const value = "a\\tb"; // string contains: a\tb (literal backslash + t, NOT a tab)
const result = dedent`x: ${value}`;

should produce x: a\tb. The interpolated value is unchanged, just like a regular template literal.

Actual

The \t inside the interpolated value gets converted to a real tab character. result is x: ab.
This also affects \n, \r, \0, \xHH, \uHHHH, etc. inside interpolated values.

Additional Info

Introduced in 1.7.2. The new .replace() chain in the escapeSpecialCharacters block runs on the fully assembled result string (static parts + interpolated values combined), so it transforms escape sequences that originated from interpolated expressions too.

Minimal reproduction:

const dedent = require("dedent"); // 1.7.2

const value = "a\\tb";
const result = dedent`x: ${value}`;
console.log(result);                        // x: a   b
console.log("Has tab?", result.includes("\t")); // true

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: accepting prsPlease, send a pull request to resolve this!type: bugSomething isn't working :(

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions