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.
Built from https://develop.svn.wordpress.org/trunk@27649


git-svn-id: http://core.svn.wordpress.org/trunk@27492 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2014-03-21 21:04:15 +00:00
parent 18a26bf513
commit 1b2bb74f76
2 changed files with 5 additions and 4 deletions

View File

@ -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

File diff suppressed because one or more lines are too long