dedent icon indicating copy to clipboard operation
dedent copied to clipboard

🐛 Bug: Escape handling is not correct

Open tvogel opened this issue 1 year ago • 3 comments

Bug Report Checklist

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

Expected

This should twice show the same string:

import dedent from "dedent"

console.log(dedent`
  This is broken:
  \\\$`);

console.log(`This is correct:
\\\$`);

Actual

It shows:

This is broken:
\\$
This is correct:
\$

Additional Info

See also: https://playcode.io/2050574

tvogel avatar Oct 18 '24 22:10 tvogel

Fun. This is the case in all dedent string versions I've tried, including the latest (1.5.3), 1.0.0, 0.6.0, and 0.1.0.

Digging into how the the tagged templates work internally:

const tagger = (strings) => strings;

console.log(tagger`From tagger:
\\\$`);
[ 'From tagger:\n\\$' ]

Seems like a bug in escapeSpecialCharacters. cc @G-Rath, what do you think?

JoshuaKGoldberg avatar Dec 01 '24 01:12 JoshuaKGoldberg

isn't this what #69 is about? dedent is escaping the $ automatically even though it doesn't need to

G-Rath avatar Dec 01 '24 18:12 G-Rath

👍 Fair. Since this issue has the cleaner repro, I'll mark that one as a duplicate of this. Thanks!

JoshuaKGoldberg avatar Dec 09 '24 18:12 JoshuaKGoldberg