PR feedback
* Doc & properly indent escapeRegExp * Add close bracket to the list of punctuation chars we search after
This commit is contained in:
parent
a87e7d6617
commit
242f5e0301
1 changed files with 7 additions and 2 deletions
|
@ -27,8 +27,13 @@ var Modal = require('../../../Modal');
|
||||||
|
|
||||||
const TRUNCATE_QUERY_LIST = 40;
|
const TRUNCATE_QUERY_LIST = 40;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Escapes a string so it can be used in a RegExp
|
||||||
|
* Basically just replaces: \ ^ $ * + ? . ( ) | { } [ ]
|
||||||
|
* From http://stackoverflow.com/a/6969486
|
||||||
|
*/
|
||||||
function escapeRegExp(str) {
|
function escapeRegExp(str) {
|
||||||
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
|
@ -326,7 +331,7 @@ module.exports = React.createClass({
|
||||||
// * The start of the string
|
// * The start of the string
|
||||||
// * Whitespace, or
|
// * Whitespace, or
|
||||||
// * A fixed number of punctuation characters
|
// * A fixed number of punctuation characters
|
||||||
let expr = new RegExp("(?:^|[\\s\\('\",\.-])" + escapeRegExp(query));
|
let expr = new RegExp("(?:^|[\\s\\(\)'\",\.-])" + escapeRegExp(query));
|
||||||
if (expr.test(name)) {
|
if (expr.test(name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue