mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Templates should not reference _.escape if "escape" delimiters are not used. [closes #484]
This commit is contained in:
26
lodash.js
26
lodash.js
@@ -6874,7 +6874,8 @@
|
||||
importsKeys = iteratorTemplate ? keys(imports) : ['_'],
|
||||
importsValues = iteratorTemplate ? values(imports) : [lodash];
|
||||
|
||||
var isEvaluating,
|
||||
var isEscaping,
|
||||
isEvaluating,
|
||||
index = 0,
|
||||
interpolate = options.interpolate || reNoMatch,
|
||||
source = "__p += '";
|
||||
@@ -6895,6 +6896,7 @@
|
||||
|
||||
// replace delimiters with snippets
|
||||
if (escapeValue) {
|
||||
isEscaping = true;
|
||||
source += "' +\n__e(" + escapeValue + ") +\n'";
|
||||
}
|
||||
if (evaluateValue) {
|
||||
@@ -6915,12 +6917,9 @@
|
||||
|
||||
// if `variable` is not specified, wrap a with-statement around the generated
|
||||
// code to add the data object to the top of the scope chain
|
||||
var variable = options.variable,
|
||||
hasVariable = variable;
|
||||
|
||||
if (!hasVariable) {
|
||||
variable = 'obj';
|
||||
source = 'with (' + variable + ') {\n' + source + '\n}\n';
|
||||
var variable = options.variable;
|
||||
if (!variable) {
|
||||
source = 'with (obj) {\n' + source + '\n}\n';
|
||||
}
|
||||
// cleanup code by stripping empty strings
|
||||
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
|
||||
@@ -6928,9 +6927,16 @@
|
||||
.replace(reEmptyStringTrailing, '$1;');
|
||||
|
||||
// frame code as the function body
|
||||
source = 'function(' + variable + ') {\n' +
|
||||
(hasVariable ? '' : variable + ' || (' + variable + ' = {});\n') +
|
||||
"var __t, __p = '', __e = _.escape" +
|
||||
source = 'function(' + (variable || 'obj') + ') {\n' +
|
||||
(variable
|
||||
? ''
|
||||
: 'obj || (obj = {});\n'
|
||||
) +
|
||||
"var __t, __p = ''" +
|
||||
(isEscaping
|
||||
? ', __e = _.escape'
|
||||
: ''
|
||||
) +
|
||||
(isEvaluating
|
||||
? ', __j = Array.prototype.join;\n' +
|
||||
"function print() { __p += __j.call(arguments, '') }\n"
|
||||
|
||||
Reference in New Issue
Block a user