From e455406b696432a9362532d37303519c5fc7e9c5 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Thu, 2 Feb 2012 13:49:35 +0000 Subject: [PATCH] MDL-31482 Lib: IE8/IE7 (even with stupid user agent) should not be 'legacy' device type --- lib/moodlelib.php | 3 ++- lib/simpletest/testmoodlelib.php | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index fa8795834699b..d7355c5699ca5 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -8206,7 +8206,8 @@ function get_device_type() { return 'tablet'; } - if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.') !== false) { + // Safe way to check for IE6 and not get false positives for some IE 7/8 users + if (substr($_SERVER['HTTP_USER_AGENT'], 0, 34) === 'Mozilla/4.0 (compatible; MSIE 6.0;') { return 'legacy'; } diff --git a/lib/simpletest/testmoodlelib.php b/lib/simpletest/testmoodlelib.php index 066624e7e6ac3..9ef7dcba9eb46 100644 --- a/lib/simpletest/testmoodlelib.php +++ b/lib/simpletest/testmoodlelib.php @@ -296,6 +296,15 @@ function test_get_browser_version_classes() { $this->assertEqual(array('gecko', 'gecko19'), get_browser_version_classes()); } + function test_get_device_type() { + // IE8 (common pattern ~1.5% of IE7/8 users have embedded IE6 agent)) + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; BT Openworld BB; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; Hotbar 10.2.197.0; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)'; + $this->assertEqual('default', get_device_type()); + // Genuine IE6 + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; AOL 9.0; Windows NT 5.1; SV1; FunWebProducts; .NET CLR 1.0.3705; Media Center PC 2.8)'; + $this->assertEqual('legacy', get_device_type()); + } + function test_fix_utf8() { // make sure valid data including other types is not changed $this->assertidentical(null, fix_utf8(null));