From 7956f0c3af8f65cd3e317ab76fcd1234fec4d1da Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 23 Dec 2014 15:09:37 +0800 Subject: [PATCH] MDL-48685 core_useragent: Correct IE 5.0 issues --- lib/classes/useragent.php | 14 +++++++------- lib/tests/useragent_test.php | 9 ++++----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/classes/useragent.php b/lib/classes/useragent.php index 2817f1ae31d..29f1a0714b6 100644 --- a/lib/classes/useragent.php +++ b/lib/classes/useragent.php @@ -176,12 +176,12 @@ class core_useragent { } } if ($this->is_useragent_mobile()) { - $this->devicetype = 'mobile'; + $this->devicetype = self::DEVICETYPE_MOBILE; } else if ($this->is_useragent_tablet()) { - $this->devicetype = 'tablet'; - } else if (substr($this->useragent, 0, 34) === 'Mozilla/4.0 (compatible; MSIE 6.0;') { - // Safe way to check for IE6 and not get false positives for some IE 7/8 users. - $this->devicetype = 'legacy'; + $this->devicetype = self::DEVICETYPE_TABLET; + } else if (self::check_ie_version('0') && !self::check_ie_version('7.0')) { + // IE 6 and before are considered legacy. + $this->devicetype = self::DEVICETYPE_LEGACY; } else { $this->devicetype = self::DEVICETYPE_DEFAULT; } @@ -884,7 +884,7 @@ class core_useragent { if ($instance->useragent === false) { // Can't be sure, just say no. $instance->supportssvg = false; - } else if (self::is_ie() and !self::check_ie_version('9')) { + } else if (self::check_ie_version('0') and !self::check_ie_version('9')) { // IE < 9 doesn't support SVG. Say no. $instance->supportssvg = false; } else if (self::is_ie() and !self::check_ie_version('10') and self::check_ie_compatibility_view()) { @@ -911,7 +911,7 @@ class core_useragent { */ public static function supports_json_contenttype() { // Modern browsers other than IE correctly supports 'application/json' media type. - if (!self::is_ie()) { + if (!self::check_ie_version('0')) { return true; } diff --git a/lib/tests/useragent_test.php b/lib/tests/useragent_test.php index 8ac8ce2048b..b4b230ca2a9 100644 --- a/lib/tests/useragent_test.php +++ b/lib/tests/useragent_test.php @@ -32,6 +32,8 @@ class core_useragent_testcase extends basic_testcase { public function user_agents_providers() { + // Note: When adding new entries to this list, please ensure that any new browser versions are added to the corresponding list. + // This ensures that regression tests are applied to all known user agents. return array( // Windows 98; Internet Explorer 5.0. array( @@ -48,8 +50,7 @@ class core_useragent_testcase extends basic_testcase { ), // IE 5.0 is a legacy browser. - // TODO Why is this not legacy!? - //'devicetype' => 'legacy', + 'devicetype' => 'legacy', 'supports_svg' => false, 'supports_json_contenttype' => false, @@ -71,8 +72,7 @@ class core_useragent_testcase extends basic_testcase { ), // IE 6.0 is a legacy browser. - // TODO Why is this not legacy!? - //'devicetype' => 'legacy', + 'devicetype' => 'legacy', 'supports_svg' => false, 'supports_json_contenttype' => false, @@ -160,7 +160,6 @@ class core_useragent_testcase extends basic_testcase { '7.0' => true, '8.0' => true, ), - 'iecompatibility' => false, 'versionclasses' => array( 'ie', 'ie8',