Skip to content
Browse files

Fixed Opera version detection.

  • Loading branch information...
1 parent 3ce160d commit 125db91771845c77cf8b2b1936356c5c3bdf62e6 @fnando committed Jun 6, 2012
Showing with 8 additions and 5 deletions.
  1. +5 −2 lib/browser.rb
  2. +3 −3 test/browser_test.rb
View
7 lib/browser.rb
@@ -28,7 +28,10 @@ class Browser
:core_media => "Apple CoreMedia"
}
- VERSION_REGEX = /(?:Version|MSIE|Opera|Firefox|Chrome|QuickTime|BlackBerry[^\/]+|CoreMedia v)[\/ ]?([a-z0-9.]+)/i
+ VERSIONS = {
+ :default => /(?:Version|MSIE|Firefox|Chrome|QuickTime|BlackBerry[^\/]+|CoreMedia v)[\/ ]?([a-z0-9.]+)/i,
+ :opera => /Opera\/.*? Version\/([\d.]+)/
+ }
TRIDENT_VERSION_REGEX = /Trident\/([0-9.]+)/
@@ -202,7 +205,7 @@ def version
# Return the full version.
def full_version
- _, v = *ua.match(VERSION_REGEX)
+ _, v = *ua.match(VERSIONS.fetch(id, VERSIONS[:default]))
v || "0.0"
end
View
6 test/browser_test.rb
@@ -11,7 +11,7 @@ class BrowserTest < Test::Unit::TestCase
IE8_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; SLCC1; Media Center PC 5.0; .NET CLR 3.5.21022)"
IE9 = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
IE9_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)"
- OPERA = "Opera/9.99 (Windows NT 5.1; U; pl) Presto/9.9.9"
+ OPERA = "Opera/9.80 (Macintosh; Intel Mac OS X 10.7.4; U; en) Presto/2.10.229 Version/11.64"
FIREFOX = "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8"
CHROME = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4"
ANDROID = "Android SDK 1.5r3: Mozilla/5.0 (Linux; U; Android 1.5; de-; sdk Build/CUPCAKE) AppleWebkit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1"
@@ -190,8 +190,8 @@ def test_detect_opera
assert_equal "Opera", @browser.name
assert @browser.opera?
assert @browser.capable?
- assert_equal "9.99", @browser.full_version
- assert_equal "9", @browser.version
+ assert_equal "11.64", @browser.full_version
+ assert_equal "11", @browser.version
end
def test_detect_firefox

0 comments on commit 125db91

Please sign in to comment.
Something went wrong with that request. Please try again.