8000 Add more checks to the `reComplexDelimiter` regexp. · lodash/lodash@9d7136c · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d7136c

Browse files
committed
Add more checks to the reComplexDelimiter regexp.
Former-commit-id: 87fba2813619882d388261a1226e75503ec9b8d0
1 parent 51a679d commit 9d7136c

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

lodash.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
var oldDash = window._;
5656

5757
/** Used to detect delimiter values that should be processed by `tokenizeEvaluate` */
58-
var reComplexDelimiter = /[-)}={(+]|\[\D/;
58+
var reComplexDelimiter = /[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/;
5959

6060
/** Used to match code generated in place of template delimiters */
6161
var reDelimiterCodeLeading = /^';\n/,

test/test.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,35 @@
671671
});
672672

673673
test('should work with complex "interpolate" delimiters', function() {
674-
var compiled = _.template('<%= a + b %>'),
675-
data = { 'a': 1, 'b': 2 };
676-
677-
equal(compiled(data), 3);
674+
_.each({
675+
'<%= a + b %>': '3',
676+
'<%= b - a %>': '1',
677+
'<%= a = b %>': '2',
678+
'<%= !a %>': 'false',
679+
'<%= ~a %>': '-2',
680+
'<%= a * b %>': '2',
681+
'<%= a / b %>': '0.5',
682+
'<%= a % b %>': '1',
683+
'<%= a >> b %>': '0',
684+
'<%= a << b %>': '4',
685+
'<%= a & b %>': '0',
686+
'<%= a ^ b %>': '3',
687+
'<%= a | b %>': '3',
688+
'<%= {}.toString.call(0) %>': '[object Number]',
689+
'<%= a.toFixed(2) %>': '1.00',
690+
'<%= obj["a"] %>': '1',
691+
'<%= delete a %>': 'true',
692+
'<%= "a" in obj %>': 'true',
693+
'<%= obj instanceof Object %>': 'true',
694+
'<%= new Boolean %>': 'false',
695+
'<%= typeof a %>': 'number',
696+
'<%= void a %>': ''
697+
}, function(value, key) {
698+
var compiled = _.template(key),
699+
data = { 'a': 1, 'b': 2 };
700+
701+
equal(compiled(data), value);
702+
});
678703
});
679704
}());
680705

0 commit comments

Comments
 (0)
0