mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +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._;
|
||||
|
||||
/** 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 */
|
||||
var reDelimiterCodeLeading = /^';\n/,
|
||||
|
||||
31
test/test.js
31
test/test.js
@@ -671,10 +671,35 @@
|
||||
});
|
||||
|
||||
test('should work with complex "interpolate" delimiters', function() {
|
||||
var compiled = _.template('<%= a + b %>'),
|
||||
data = { 'a': 1, 'b': 2 };
|
||||
_.each({
|
||||
'<%= 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