From f0abc9b7e00f08803bd624e7863aa58e7cdbfc4c Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Fri, 21 Mar 2014 21:03:59 +0000 Subject: [PATCH] Themes: Improve RegExp pattern for search. * The replacement of spaces is now done globally. * The search term is now escaped for RegExp meta characters. props westonruter for the hint. fixes #27479. git-svn-id: https://develop.svn.wordpress.org/trunk@27649 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/theme.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/js/theme.js b/src/wp-admin/js/theme.js index d5dc9de10d..bb58f52fa5 100644 --- a/src/wp-admin/js/theme.js +++ b/src/wp-admin/js/theme.js @@ -179,11 +179,12 @@ themes.Collection = Backbone.Collection.extend({ // Start with a full collection this.reset( themes.data.themes, { silent: true } ); - // The RegExp object to match - // + // Escape the term string for RegExp meta characters + term = term.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' ); + // Consider spaces as word delimiters and match the whole string // so matching terms can be combined - term = term.replace( ' ', ')(?=.*' ); + term = term.replace( / /g, ')(?=.*' ); match = new RegExp( '^(?=.*' + term + ').+', 'i' ); // Find results