From 99c2d424af62f7f2fd6273c3369eb6b2c814ac5c Mon Sep 17 00:00:00 2001 From: Joe Farro Date: Tue, 26 Sep 2017 10:57:21 -0400 Subject: [PATCH] Better var name and added a comment --- src/components/SearchTracePage/SearchDropdownInput.js | 6 +++--- src/utils/regexp-escape.js | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/SearchTracePage/SearchDropdownInput.js b/src/components/SearchTracePage/SearchDropdownInput.js index b0c566d3d1..60a080f6e2 100644 --- a/src/components/SearchTracePage/SearchDropdownInput.js +++ b/src/components/SearchTracePage/SearchDropdownInput.js @@ -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; diff --git a/src/utils/regexp-escape.js b/src/utils/regexp-escape.js index f40e63f840..844b2bf44a 100644 --- a/src/utils/regexp-escape.js +++ b/src/utils/regexp-escape.js @@ -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, '\\$&'); }