Skip to content

Commit

Permalink
ie in compatibility mode is not the trident version
Browse files Browse the repository at this point in the history
  • Loading branch information
outerim committed Apr 11, 2012
1 parent 77306c8 commit 9b34624
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
16 changes: 7 additions & 9 deletions lib/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Browser

VERSION_REGEX = /(?:Version|MSIE|Opera|Firefox|Chrome|QuickTime|BlackBerry[^\/]+|CoreMedia v)[\/ ]?([a-z0-9.]+)/i

COMPATIBILITY_VIEW_REGEXP = /Trident\/([0-9.]+)/
TRIDENT_VERSION_REGEX = /Trident\/([0-9.]+)/

LANGUAGES = {
"af" => "Afrikaans",
Expand Down Expand Up @@ -202,13 +202,7 @@ def version

# Return the full version.
def full_version
if compatibility_view?
_, v = *ua.match(COMPATIBILITY_VIEW_REGEXP)
v.gsub!(/^([0-9])/) { $1.to_i + 4 }
else
_, v = *ua.match(VERSION_REGEX)
end

_, v = *ua.match(VERSION_REGEX)
v || "0.0"
end

Expand All @@ -218,7 +212,11 @@ def capable?
end

def compatibility_view?
ie? && ua.match(COMPATIBILITY_VIEW_REGEXP)
if ie? && ua.match(TRIDENT_VERSION_REGEX)
version.to_i < ($1.to_i + 4)
else
false
end
end

# Detect if browser is WebKit-based.
Expand Down
16 changes: 10 additions & 6 deletions test/browser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def test_detect_ie8
assert @browser.ie?
assert @browser.ie8?
assert @browser.capable?
assert !@browser.compatibility_view?
assert_equal "8.0", @browser.full_version
assert_equal "8", @browser.version
end
Expand All @@ -146,11 +147,12 @@ def test_detect_ie8_in_compatibility_view

assert_equal "Internet Explorer", @browser.name
assert @browser.ie?
assert @browser.ie8?
assert @browser.ie7?
assert !@browser.ie8?
assert @browser.capable?
assert @browser.compatibility_view?
assert_equal "8.0", @browser.full_version
assert_equal "8", @browser.version
assert_equal "7.0", @browser.full_version
assert_equal "7", @browser.version
end

def test_detect_ie9
Expand All @@ -160,6 +162,7 @@ def test_detect_ie9
assert @browser.ie?
assert @browser.ie9?
assert @browser.capable?
assert !@browser.compatibility_view?
assert_equal "9.0", @browser.full_version
assert_equal "9", @browser.version
end
Expand All @@ -169,11 +172,12 @@ def test_detect_ie9_in_compatibility_view

assert_equal "Internet Explorer", @browser.name
assert @browser.ie?
assert @browser.ie9?
assert @browser.ie7?
assert !@browser.ie9?
assert @browser.capable?
assert @browser.compatibility_view?
assert_equal "9.0", @browser.full_version
assert_equal "9", @browser.version
assert_equal "7.0", @browser.full_version
assert_equal "7", @browser.version
end

def test_detect_opera
Expand Down

0 comments on commit 9b34624

Please sign in to comment.