Open Izzmo opened 8 years ago
The documentation for lodash indicates that \\
can be used to escape the open and close angle brackets.
https://lodash.com/docs#template
so for example:
replacements: [{
from: 'something',
to: '<script src="\\<%=ConfigurationManager.AppSettings("something")%\\>"></script>'
}]
@nycdotnet the problem is that those output like:
<script src="\<%=ConfigurationManager.AppSettings("something")%\>"></script>
instead of
<script src="<%=ConfigurationManager.AppSettings("something")%>"></script>
Not sure why it's keeping the extra slash in there.
It's most likely upstream issue. Did you try to test it with native lodash _.template(...)
? Does it produce those slashes too?
@ArmorDarks Sort of.
This adds a slash (making it a single backslash outputs fine though..):
let x = _.template('test <%= test %>!');
x({ test: '<script src="\\<%=ConfigurationManager.AppSettings("something")%\\>"></script>' });
// output: "test <script src="\<%=ConfigurationManager.AppSettings("something")%\>"></script>!"
Oh, now I see why it doesn't work.
Here is example from docs:
// Use backslashes to treat delimiters as plain text.
var compiled = _.template('<%= "\\<%- value %\\>" %>');
compiled({ 'value': 'ignored' });
// ➜ '<%- value %>'
Please, note that you should wrap escaped template into template tags too to make it work.
_.template('\\<%- value %\\>')()
\\ returns `\<%- "value" %\>`
_.template('<%= "\\<%- value %\\>" %>')()
\\ returns `<%- value %>`
Though, what is really strange, while '<%= "\\<%- value %\\>" %>'
works in lodash templates, Grunt for some reasons completely ignores escaping and trying to process whole template, which results in Warning: An error occurred while processing a template (value is not defined)
.
So, in the end of all, it's Grunt's issue.
@ArmorDarks thanks for writing that out, that helps. So, now, where in the Grunt code should this be fixed, do you think?
Simple question: is it possible to keep template strings from getting processed?
I shouldn't have to do this: