Making WordPress.org

Changeset 5048


Ignore:
Timestamp:
03/02/2017 09:16:02 PM (8 years ago)
Author:
ocean90
Message:

Rosetta Roles: Don't use the escaped search term for calculating the match score.

Fixes #2540.

Location:
sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/js/rosetta-roles.js

    r4929 r5048  
    187187        // @uses RegExp
    188188        search: function( term ) {
    189             var match, results;
     189            var match, results, escapedTerm;
    190190
    191191            // Start with a full collection
     
    193193
    194194            // Escape the term string for RegExp meta characters
    195             term = term.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' );
     195            escapedTerm = term.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' );
    196196
    197197            // Consider spaces as word delimiters and match the whole string
    198198            // so matching terms can be combined
    199             term = term.replace( / /g, ')(?=.*' );
    200             match = new RegExp( '^(?=.*' + term + ').+', 'i' );
     199            escapedTerm = escapedTerm.replace( / /g, ')(?=.*' );
     200            match = new RegExp( '^(?=.*' + escapedTerm + ').+', 'i' );
    201201
    202202            results = this.filter( function( project ) {
     
    204204                if ( match.test( haystack ) ) {
    205205                    _.each( haystack, function( word ) {
    206                         var score = word.score( term );
     206                        var score = word.score( term, .5 );
    207207                        project.set( 'matchScore', Math.max( score, project.get( 'matchScore' ) ) );
    208208                    });
  • sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php

    r4929 r5048  
    109109    public static function enqueue_scripts() {
    110110        wp_enqueue_script( 'string_score', plugins_url( '/js/string_score.min.js', __FILE__ ), array(), '0.1.22', true );
    111         wp_enqueue_script( 'rosetta-roles', plugins_url( '/js/rosetta-roles.js', __FILE__ ), array( 'jquery', 'wp-backbone', 'string_score' ), '10', true );
     111        wp_enqueue_script( 'rosetta-roles', plugins_url( '/js/rosetta-roles.js', __FILE__ ), array( 'jquery', 'wp-backbone', 'string_score' ), '11', true );
    112112    }
    113113
Note: See TracChangeset for help on using the changeset viewer.