Skip to:
Content

BuddyPress.org

Changeset 12219


Ignore:
Timestamp:
09/07/2018 03:43:17 AM (6 years ago)
Author:
imath
Message:

BP Nouveau: Improve special characters management in Members search

[12201] only partly fixed AJAX search requests into the Members directory :

  • The search input needs to output URL decoded characters.
  • Special characters such as ">" or "<", when directly typed into the search input, need to be URL encoded.

Props n0barcode

Fixes #7962 (trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/js/buddypress-nouveau.js

    r12201 r12219  
    22/* jshint devel: true */
    33/* jshint browser: true */
    4 /* @version 3.0.0 */
     4/* @version 3.2.0 */
    55window.wp = window.wp || {};
    66window.bp = window.bp || {};
     
    160160
    161161            return params;
     162        },
     163
     164        /**
     165         * URL Decode a query variable.
     166         *
     167         * @param  {string} qv    The query variable to decode.
     168         * @param  {object} chars The specific characters to use. Optionnal.
     169         * @return {string}       The URL decoded variable.
     170         */
     171        urlDecode: function( qv, chars ) {
     172            var specialChars = chars || {
     173                amp: '&',
     174                lt: '<',
     175                gt: '>',
     176                quot: '"',
     177                '#039': '\''
     178            };
     179
     180            return decodeURIComponent( qv.replace( /\+/g, ' ' ) ).replace( /&([^;]+);/g, function( v, q ) {
     181                return specialChars[q] || '';
     182            } );
    162183        },
    163184
     
    239260            }
    240261
     262            // Prepare the search terms for the request
     263            if ( data.search_terms ) {
     264                data.search_terms = data.search_terms.replace( /</g, '&lt;' ).replace( />/g, '&gt;' );
     265            }
     266
    241267            // Set session's data
    242268            if ( null !== data.scope ) {
     
    358384
    359385                    if ( search_terms ) {
    360                         search_terms = decodeURIComponent( search_terms.replace( /\+/g, ' ' ) );
     386                        search_terms = self.urlDecode( search_terms );
    361387                        $( '#buddypress [data-bp-search="' + object + '"] input[type=search]' ).val( search_terms );
    362388                    }
Note: See TracChangeset for help on using the changeset viewer.