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
This commit is contained in:
Dominik Schilling (ocean90) 2014-03-21 21:03:59 +00:00
parent 4db18a113d
commit f0abc9b7e0
1 changed files with 4 additions and 3 deletions

View File

@ -179,11 +179,12 @@ themes.Collection = Backbone.Collection.extend({
// Start with a full collection // Start with a full collection
this.reset( themes.data.themes, { silent: true } ); 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 // Consider spaces as word delimiters and match the whole string
// so matching terms can be combined // so matching terms can be combined
term = term.replace( ' ', ')(?=.*' ); term = term.replace( / /g, ')(?=.*' );
match = new RegExp( '^(?=.*' + term + ').+', 'i' ); match = new RegExp( '^(?=.*' + term + ').+', 'i' );
// Find results // Find results