Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

reversed <%- %> and <%= %> #24

Open
charmingzuo opened this issue Jan 18, 2018 · 2 comments
Open

reversed <%- %> and <%= %> #24

charmingzuo opened this issue Jan 18, 2018 · 2 comments

Comments

@charmingzuo
Copy link

charmingzuo commented Jan 18, 2018

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>
@okonet
Copy link
Collaborator

okonet commented Jan 19, 2018

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

@axelpale
Copy link
Contributor

axelpale commented Mar 18, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants