Ensure _.escapeRegExp escapes line terminators.

This commit is contained in:
jdalton
2015-06-19 22:04:36 -07:00
parent 4896c725b6
commit 192667d65f
2 changed files with 19 additions and 19 deletions

View File

@@ -94,11 +94,10 @@
rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
/**
* Used to match `RegExp` [special characters](http://www.regular-expressions.info/characters.html#special).
* In addition to special characters the forward slash is escaped to allow for
* easier `eval` use and `Function` compilation.
* Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
* and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
*/
var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g,
var reRegExpChars = /[\/^$\\.*+?()[\]{}|\n\r\u2028\u2029]/g,
reHasRegExpChars = RegExp(reRegExpChars.source);
/** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
@@ -10491,7 +10490,7 @@
function escapeRegExp(string) {
string = baseToString(string);
return (string && reHasRegExpChars.test(string))
? string.replace(reRegExpChars, '\\$&')
? string.replace(reRegExpChars, function(chr) { return '\\' + (stringEscapes[chr] || chr); })
: (string || '(?:)');
}