[wp-trac] [WordPress Trac] #39041: Installed themes search displays theme author names when the search term is a space

WordPress Trac noreply at wordpress.org
Sat Dec 3 18:14:21 UTC 2016


#39041: Installed themes search displays theme author names when the search term is
a space
--------------------------+-----------------------------
 Reporter:  afercia       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Themes        |    Version:
 Severity:  normal        |   Keywords:  has-screenshots
  Focuses:  javascript    |
--------------------------+-----------------------------
 Go in the themes screen and insert a single space in the search field: the
 theme author names will appear in the theme thumbnails:

 [[Image(https://cldup.com/ZClQwM6qwX.jpg)]]

 Theme author names are intended to appear just when the search term
 matches the author name. Side note: wondering how many users are aware of
 this "hidden" feature.

 Looking a bit into `theme.js`, turns out that thanks to this replacement:

 `term = term.replace( / /g, ')(?=.*' );`

 the regular expression
 `match = new RegExp( '^(?=.*' + term + ').+', 'i' );`
 becomes
 `match = new RegExp( '^(?=.*)(?=.*).+', 'i' );`

 so it matches any author name and it is longer than 2 characters:
 {{{
 if ( match.test( data.get( 'author' ) ) && term.length > 2 ) {
         data.set( 'displayAuthor', true );
 }
 }}}

 Without changing the regex, maybe the best option would be using
 `jQuery.trim( term )` (because IE 8 is still supported) and then if the
 term is empty, just return early. Also, I'd like to quote @azaozz and
 recommend that this kind of searches should fire after a minimum number of
 typed characters, see:
 https://core.trac.wordpress.org/ticket/37233#comment:21
 > ideally it should trigger after 2 ASCII chars or one high UTF-8 char. We
 can standardize this for all similar cases in core, there are at least 6-7
 other places.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39041>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list