Skip to content

Commit

Permalink
Better var name and added a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffon committed Sep 26, 2017
1 parent ae5702f commit 99c2d42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/SearchTracePage/SearchDropdownInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export default class SearchDropdownInput extends Component {
}
onSearch(_, searchText) {
const { items, maxResults } = this.props;
const rxStr = regexpEscape(searchText);
const rx = new RegExp(rxStr, 'i');
return items.filter(v => rx.test(v.text)).slice(0, maxResults);
const regexStr = regexpEscape(searchText);
const regex = new RegExp(regexStr, 'i');
return items.filter(v => regex.test(v.text)).slice(0, maxResults);
}
render() {
const { input: { value, onChange } } = this.props;
Expand Down
3 changes: 3 additions & 0 deletions src/utils/regexp-escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

/**
* Escape the meta-caharacters used in regular expressions.
*/
export default function regexpEscape(s) {
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
}

0 comments on commit 99c2d42

Please sign in to comment.