mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Add test for _.escapeRegExp with eval and Function.
This commit is contained in:
23
test/test.js
23
test/test.js
@@ -4195,19 +4195,30 @@
|
||||
QUnit.module('lodash.escapeRegExp');
|
||||
|
||||
(function() {
|
||||
var escaped = '\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\/\\\\',
|
||||
unescaped = '.*+?^${}()|[\]\/\\';
|
||||
|
||||
escaped += escaped;
|
||||
unescaped += unescaped;
|
||||
|
||||
test('should escape values', 1, function() {
|
||||
var escaped = '\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\/\\\\',
|
||||
unescaped = '.*+?^${}()|[\]\/\\';
|
||||
|
||||
escaped += escaped;
|
||||
unescaped += unescaped;
|
||||
|
||||
strictEqual(_.escapeRegExp(unescaped), escaped);
|
||||
});
|
||||
|
||||
test('should handle strings with nothing to escape', 1, function() {
|
||||
strictEqual(_.escapeRegExp('abc'), 'abc');
|
||||
});
|
||||
|
||||
test('should work with `eval` and `Function`', 2, function() {
|
||||
var string = '[lodash](https://lodash.com/)',
|
||||
escaped = _.escapeRegExp(string),
|
||||
regexp = eval('(/' + escaped + '/)');
|
||||
|
||||
ok(regexp.test(string));
|
||||
|
||||
regexp = Function('return /' + escaped + '/')();
|
||||
ok(regexp.test(string));
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user