WordPress.org

Making WordPress.org

Changeset 5951


Ignore:
Timestamp:
09/21/2017 08:17:25 PM (22 months ago)
Author:
coffee2code
Message:

Browse Happy API: More plainly short-circuit browser data fetching for mobile platforms.

  • Initializes all array elements in browsehappy_parse_user_agent()
  • Removes short-circuit that assigned platform name to browser name for mobile platforms
  • Fixes 4 of 5 failing tests

It appears that during user-agent parsing for mobile platforms, the browser name is intentionally overridden to be the platform name so as to be the name passed when requesting browser info. Since no browsers are defined using the platform name (e.g. "iPad"), no info is obtained, effectively bypassing checks for iPad/iPhone/Android mobile browsers at this time. This change make this much clearer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/core/browse-happy/1.0/parse.php

    r5949 r5951  
    2525 */
    2626function browsehappy_parse_user_agent( $user_agent ) {
    27     $data = array();
     27    $data = array(
     28        'name'            => '',
     29        'version'         => '',
     30        'platform'        => '',
     31        'update_url'      => '',
     32        'img_src'         => '',
     33        'img_src_ssl'     => '',
     34        'current_version' => '',
     35        'upgrade'         => false,
     36        'insecure'        => false,
     37    );
    2838
    2939    if ( preg_match(
     
    95105    }
    96106
    97     if ( in_array( $data['platform'], array( 'Android', 'iPad', 'iPhone' ) ) ) {
    98         $data['name'] = $data['platform'];
    99     }
    100 
    101107    // If Version/x.x.x was specified in UA string
    102108    if ( ! empty( $version ) ) {
    103109        $data['version'] = $version;
     110    }
     111
     112    // Don't fetch additional browser data for non-mobile platform browsers.
     113    if ( in_array( $data['platform'], array( 'Android', 'iPad', 'iPhone' ) ) ) {
     114        return $data;
    104115    }
    105116
Note: See TracChangeset for help on using the changeset viewer.