(bug 42604) fix faulty browser detection code for Opera
authorMatmaRex <matma.rex@gmail.com>
Sat, 1 Dec 2012 13:34:29 +0000 (14:34 +0100)
committerGerrit Code Review <gerrit@wikimedia.org>
Sun, 9 Dec 2012 16:41:46 +0000 (16:41 +0000)
Opera's `navigator.userAgent` might not include the "Version/major.minor"
part, causing the code relying on it being present to blow up. This patch
fixes the issue.

Also added tests for Opera.

Change-Id: I9ceb7517e00042366e45cf13aa89262ed19709c0

resources/jquery/jquery.client.js
tests/qunit/suites/resources/jquery/jquery.client.test.js

index b35dbbb..ae6f2b0 100644 (file)
                                }
                                // Expose Opera 10's lies about being Opera 9.8
                                if ( name === 'opera' && version >= 9.8) {
-                                       version = ua.match( /version\/([0-9\.]*)/i )[1] || 10;
+                                       match = ua.match( /version\/([0-9\.]*)/i );
+                                       if ( match && match[1] ) {
+                                               version = match[1];
+                                       } else {
+                                               version = '10';
+                                       }
                                }
                                versionNumber = parseFloat( version, 10 ) || 0.0;
 
index bbc8852..29c6657 100644 (file)
                                }
                        },
                        // Safari 5
-                       // Opera 10
+                       // Opera 10+
+                       'Opera/9.80 (Windows NT 5.1)': {
+                               title: 'Opera 10+ (exact version unspecified)',
+                               platform: 'Win32',
+                               profile: {
+                                       name: 'opera',
+                                       layout: 'presto',
+                                       layoutVersion: 'unknown',
+                                       platform: 'win',
+                                       version: '10',
+                                       versionBase: '10',
+                                       versionNumber: 10
+                               },
+                               wikiEditor: {
+                                       ltr: true,
+                                       rtl: true
+                               }
+                       },
+                       // Opera 12
+                       'Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.11': {
+                               title: 'Opera 12',
+                               platform: 'Win32',
+                               profile: {
+                                       name: 'opera',
+                                       layout: 'presto',
+                                       layoutVersion: 'unknown',
+                                       platform: 'win',
+                                       version: '12.11',
+                                       versionBase: '12',
+                                       versionNumber: 12.11
+                               },
+                               wikiEditor: {
+                                       ltr: true,
+                                       rtl: true
+                               }
+                       },
                        // Chrome 5
                        // Chrome 6
                        // Chrome 7