handlebars-lang / docs

Documentation for handlebars.js and the handlebars-language
https://handlebarsjs.com
MIT License
36 stars 47 forks source link

Update escape character usage #125

Closed hanifaudah closed 1 year ago

hanifaudah commented 1 year ago

Hi, I found that using single back slashes don't work anymore for version 4.7.7. Double slashes work to escape the characters.

Sample code I used to prove this:

const expectedString = `{{escaped}}`
console.log('single slash escape:', handlebars.compile(`\{{escaped}}`)() == expectedString)
console.log('double slash escape:', handlebars.compile(`\\{{escaped}}`)() == expectedString)

image image

ilharp commented 1 year ago

The string literal '\\' represents string \ in JavaScript. So '\{{escaped}}' becomes {{escaped}} (escape miss) and '\\{{escaped}}' becomes \{{escaped}}.

Try:

console.log(`\{{escaped}}`)  // {{escaped}}
console.log(`\\{{escaped}}`) // \{{escaped}}

If you're not familiar with JavaScript:

hanifaudah commented 1 year ago

The string literal '\\' represents string \ in JavaScript. So '\{{escaped}}' becomes {{escaped}} (escape miss) and '\\{{escaped}}' becomes \{{escaped}}.

Try:

console.log(`\{{escaped}}`)  // {{escaped}}
console.log(`\\{{escaped}}`) // \{{escaped}}

If you're not familiar with JavaScript:

I see, thanks for the feedback.