[BUGFIX] ClientUtility does not detect Internet Explorer 11 87/25887/2
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 1 Dec 2013 14:33:13 +0000 (15:33 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Mon, 2 Dec 2013 19:19:53 +0000 (20:19 +0100)
Since the Release of Microsoft IE 11 there is no "MSIE" hint in
its user agent header anymore. Therefore the existing patterns
fail and the browser is detected as unknown browser.

TYPO3 deactivates several features for unknown browser. As a
result f.e. the RTE does not load.

This change adds special treatment for IE11+ by introducing an
additional regular expression matching the new user agent format
and looking for the Trident engine to be present.

In addition unit tests for common IE 9-11 user agents are added.

Change-Id: I389f344a498ac77f3e6445656dd125fd5d236a98
Resolves: #54124
Releases: 6.2, 6.1, 6.0, 4.7, 4.5
Reviewed-on: https://review.typo3.org/25887
Reviewed-by: Markus Klein
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
t3lib/utility/class.t3lib_utility_client.php
tests/t3lib/utility/t3lib_utility_clientTest.php

index 89023cc..bdb0fab 100644 (file)
@@ -77,9 +77,21 @@ final class t3lib_utility_Client {
                $pattern = '#(?P<browser>' . join('|', $known) . ')[/ ]+(?P<version>[0-9]+(?:\.[0-9]+)?)#';
                        // Find all phrases (or return empty array if none found)
                if (!preg_match_all($pattern, strtolower($userAgent), $matches)) {
-                       $browserInfo['browser'] = 'unknown';
-                       $browserInfo['version'] = '';
-                       $browserInfo['all'] = array();
+                               // Microsoft Internet-Explorer 11 does not have a sign of "MSIE" or so in the useragent.
+                               // All checks from the pattern above fail here. Look for a special combination of
+                               // "Mozilla/5.0" in front, "Trident/7.0" in the middle and "like Gecko" at the end.
+                               // The version (revision) is given as "; rv:11.0" in the useragent then.
+                       unset($matches);
+                       $pattern = '#mozilla/5\\.0 \\(.*trident/7\\.0.*; rv:(?P<version>[0-9]+(?:\\.[0-9]+)?)\\) like gecko#i';
+                       if (preg_match_all($pattern, $userAgent, $matches)) {
+                               $browserInfo['browser'] = 'msie';
+                               $browserInfo['version'] = $matches['version'][0];
+                               $browserInfo['all'] = array('msie' => $matches['version'][0]);
+                       } else {
+                               $browserInfo['browser'] = 'unknown';
+                               $browserInfo['version'] = '';
+                               $browserInfo['all'] = array();
+                       }
                } else {
                                // Since some UAs have more than one phrase (e.g Firefox has a Gecko phrase,
                                // Opera 7,8 have a MSIE phrase), use the last one found (the right-most one
@@ -89,6 +101,7 @@ final class t3lib_utility_Client {
                        $browserInfo['browser'] = $matches['browser'][$lastIndex];
                        $browserInfo['version'] = $browserInfo['browser'] === 'msie' ? $matches['version'][0] : $matches['version'][$lastIndex];
                                //But return all parsed browsers / version in an extra array
+                       $browserInfo['all'] = array();
                        for ($i = 0; $i <= $lastIndex; $i++) {
                                if (!isset($browserInfo['all'][$matches['browser'][$i]])) {
                                        $browserInfo['all'][$matches['browser'][$i]] = $matches['version'][$i];
index 062d827..854294b 100644 (file)
@@ -68,19 +68,16 @@ class t3lib_utility_clientTest extends tx_phpunit_testcase {
         * @param array $expectedMembers array with expected browser/version for given userAgent strings
         */
        private function analyzeUserAgentStrings($browserStrings, $expectedMembers) {
-               $compare = $expected = array();
+               $actual = $expected = array();
                foreach ($browserStrings as $browserString) {
                        $infoArray = t3lib_utility_Client::getBrowserInfo($browserString);
                        $expected[] = $expectedMembers;
-                       $compare[] = array(
+                       $actual[] = array(
                                'browser' => $infoArray['browser'],
-                               'version' => substr($infoArray['version'], 0, 1)
+                               'version' => array_shift(explode('.', $infoArray['version']))
                        );
                }
-               $this->assertEquals(
-                       $expected,
-                       $compare
-               );
+               $this->assertSame($expected, $actual);
        }
 
 
@@ -146,7 +143,9 @@ class t3lib_utility_clientTest extends tx_phpunit_testcase {
                        'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; YPC 3.2.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)',
                        'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; Media Center PC 5.0; .NET CLR 2.0.50727)',
                        'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 3.0.04506)',
-                       'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET CLR 1.1.4322)'
+                       'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET CLR 1.1.4322)',
+                       'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)',
+                       'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)',
                );
                $expectedMembers = array(
                        'browser' => 'msie',
@@ -192,6 +191,49 @@ class t3lib_utility_clientTest extends tx_phpunit_testcase {
        /**
         * @test
         */
+       public function checkBrowserInfoIE9() {
+               $browserStrings = array(
+                       'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)',
+               );
+               $expectedMembers = array(
+                       'browser' => 'msie',
+                       'version' => '9'
+               );
+               $this->analyzeUserAgentStrings($browserStrings, $expectedMembers);
+       }
+
+       /**
+        * @test
+        */
+       public function checkBrowserInfoIE10() {
+               $browserStrings = array(
+                       'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)',
+               );
+               $expectedMembers = array(
+                       'browser' => 'msie',
+                       'version' => '10'
+               );
+               $this->analyzeUserAgentStrings($browserStrings, $expectedMembers);
+       }
+
+       /**
+        * @test
+        */
+       public function checkBrowserInfoIE11() {
+               $browserStrings = array(
+                       'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
+                       'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko',
+               );
+               $expectedMembers = array(
+                       'browser' => 'msie',
+                       'version' => '11'
+               );
+               $this->analyzeUserAgentStrings($browserStrings, $expectedMembers);
+       }
+
+       /**
+        * @test
+        */
        public function checkGeckoVersion() {
                $userAgentString = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3';
                $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);