ejs-loader icon indicating copy to clipboard operation
ejs-loader copied to clipboard

reversed <%- %> and <%= %>

Open charmingzuo opened this issue 6 years ago • 2 comments

Escaped output with <%= %> (escape function configurable) Unescaped raw output with <%- %>

but my test results is reversed

test code:

<div><%- '<img/>'%></div>

results:

<div>&lt;img/&gt;</div>

the write results should be:

<div><img/></div>

charmingzuo avatar Jan 18 '18 09:01 charmingzuo

Is this a documentation issue? Please send a fix in a PR.

okonet avatar Jan 19 '18 10:01 okonet

All resources I found associate = with escaped output and - with raw unescaped output. Please see tj/ejs features, ejs.co docs and their implementation: Line 764 of ejs.js at GitHub.

In contrast, Lodash's implementation has things other way around, associating - with escaped output and = with raw output. Lodash might have taken a wrong step here. The _.templateSettings refer the default settings to follow Embedded Ruby and template literals of ES2015 but neither has a strong opinion on the matter. Embedded Ruby associates <%- with slurping and ES2015 uses String.raw prefix for unescaped template strings.

See also the default Lodash _.templateSettings. Maybe the property escape has something to do with this? Maybe the default setting could be overridden in ejs-loader?

@okonet For me this seems to be a Lodash issue. I went and opened an issue there.

axelpale avatar Mar 18 '18 23:03 axelpale