mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Add more checks to the reComplexDelimiter regexp.
Former-commit-id: 87fba2813619882d388261a1226e75503ec9b8d0
This commit is contained in:
@@ -55,7 +55,7 @@
|
|||||||
var oldDash = window._;
|
var oldDash = window._;
|
||||||
|
|
||||||
/** Used to detect delimiter values that should be processed by `tokenizeEvaluate` */
|
/** Used to detect delimiter values that should be processed by `tokenizeEvaluate` */
|
||||||
var reComplexDelimiter = /[-)}={(+]|\[\D/;
|
var reComplexDelimiter = /[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/;
|
||||||
|
|
||||||
/** Used to match code generated in place of template delimiters */
|
/** Used to match code generated in place of template delimiters */
|
||||||
var reDelimiterCodeLeading = /^';\n/,
|
var reDelimiterCodeLeading = /^';\n/,
|
||||||
|
|||||||
31
test/test.js
31
test/test.js
@@ -671,10 +671,35 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should work with complex "interpolate" delimiters', function() {
|
test('should work with complex "interpolate" delimiters', function() {
|
||||||
var compiled = _.template('<%= a + b %>'),
|
_.each({
|
||||||
data = { 'a': 1, 'b': 2 };
|
'<%= a + b %>': '3',
|
||||||
|
'<%= b - a %>': '1',
|
||||||
|
'<%= a = b %>': '2',
|
||||||
|
'<%= !a %>': 'false',
|
||||||
|
'<%= ~a %>': '-2',
|
||||||
|
'<%= a * b %>': '2',
|
||||||
|
'<%= a / b %>': '0.5',
|
||||||
|
'<%= a % b %>': '1',
|
||||||
|
'<%= a >> b %>': '0',
|
||||||
|
'<%= a << b %>': '4',
|
||||||
|
'<%= a & b %>': '0',
|
||||||
|
'<%= a ^ b %>': '3',
|
||||||
|
'<%= a | b %>': '3',
|
||||||
|
'<%= {}.toString.call(0) %>': '[object Number]',
|
||||||
|
'<%= a.toFixed(2) %>': '1.00',
|
||||||
|
'<%= obj["a"] %>': '1',
|
||||||
|
'<%= delete a %>': 'true',
|
||||||
|
'<%= "a" in obj %>': 'true',
|
||||||
|
'<%= obj instanceof Object %>': 'true',
|
||||||
|
'<%= new Boolean %>': 'false',
|
||||||
|
'<%= typeof a %>': 'number',
|
||||||
|
'<%= void a %>': ''
|
||||||
|
}, function(value, key) {
|
||||||
|
var compiled = _.template(key),
|
||||||
|
data = { 'a': 1, 'b': 2 };
|
||||||
|
|
||||||
equal(compiled(data), 3);
|
equal(compiled(data), value);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user