WordPress.org

Making WordPress.org

Changeset 5986


Ignore:
Timestamp:
10/02/2017 05:04:34 PM (2 years ago)
Author:
coffee2code
Message:

Browse Happy API: Check for Trident token at a higher priority than MSIE token when determining the version of IE.

Allows proper version of IE to be detected, even if browser mode is employed to emulate another version of IE.

Location:
sites/trunk/api.wordpress.org/public_html/core/browse-happy/1.0
Files:
2 edited

Legend:

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

    r5985 r5986  
    148148        }
    149149        $data['version'] = $result['version'][ $key ];
    150     } elseif ( 'MSIE' == $result['name'][0] ) {
     150    }
     151    // Trident (Internet Explorer)
     152    elseif ( false !== ( $key = array_search( 'Trident', $result['name'] ) ) ) {
     153        // IE 8-10 more reliably report version via Trident token than MSIE token.
     154        // IE 11 uses Trident token without an MSIE token.
     155        // https://msdn.microsoft.com/library/hh869301(v=vs.85).aspx
     156        if ( $key2 = array_search( 'IEMobile', $result['name'] ) ) {
     157            $data['name'] = 'Internet Explorer Mobile';
     158            $data['version'] = $result['version'][ $key2 ];
     159        } else {
     160            $data['name'] = 'Internet Explorer';
     161            $trident_ie_mapping = array(
     162                '4.0' => '8.0',
     163                '5.0' => '9.0',
     164                '6.0' => '10.0',
     165                '7.0' => '11.0',
     166            );
     167            $ver = $result['version'][ $key ];
     168            $data['version'] = $trident_ie_mapping[ $ver ] ?? $ver;
     169        }
     170    }
     171    // Internet Explorer (pre v8.0)
     172    elseif ( 'MSIE' == $result['name'][0] ) {
    151173        if ( $key = array_search( 'IEMobile', $result['name'] ) ) {
    152174            $data['name'] = 'Internet Explorer Mobile';
     
    156178        }
    157179        $data['version'] = $result['version'][ $key ];
    158     } elseif ( 'Trident' == $result['name'][0] ) {
    159         // IE 11 and beyond have switched to Trident
    160         // http://msdn.microsoft.com/en-us/library/ie/hh869301%28v=vs.85%29.aspx
    161         if ( $key = array_search( 'IEMobile', $result['name'] ) ) {
    162             $data['name'] = 'Internet Explorer Mobile';
    163         } else {
    164             $data['name'] = 'Internet Explorer';
    165         }
    166         if ( '7.0' == $result['version'][0] ) {
    167             $data['version'] = '11.0';
    168         }
    169     } else {
     180    }
     181    // Fall back to whatever is being reported.
     182    else {
    170183        $data['name'] = $result['name'][0];
    171184        $data['version'] = $result['version'][0];
  • sites/trunk/api.wordpress.org/public_html/core/browse-happy/1.0/tests/phpunit/tests/browse-happy.php

    r5985 r5986  
    263263                'Windows Internet Explorer 11.0',
    264264            ],
     265            [ // Fictitious Trident version
     266                'Mozilla/5.0 (Windows NT 6.3; Trident/34.0; rv:38.0) like Gecko',
     267                'Windows Internet Explorer 34.0',
     268            ],
    265269            [
    266270                'Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0) Asus;Galaxy6',
Note: See TracChangeset for help on using the changeset viewer.