Skip to content

Commit acc0956

Browse files
koesie10fnando
authored andcommitted
Fix iOS 10+ version detection (fnando#422)
1 parent c734ccf commit acc0956

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Handle Snapchat user agents that have a space or an empty string instead of a slash before the version.
6+
- Fix iOS 10+ version detection.
67
- Add fallback versions for instagram and snapchat to avoid NoMethodErrors on unexpected user agents.
78

89
## 2.7.0

lib/browser/platform/ios.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Browser
44
class Platform
55
class IOS < Base
66
MATCHER = /(iPhone|iPad|iPod)/.freeze
7-
VERSION_MATCHER = /OS ((?<major>\d)_(?<minor>\d)_?(?<patch>\d)?)/.freeze
7+
VERSION_MATCHER = /OS ((?<major>\d+)_(?<minor>\d+)_?(?<patch>\d+)?)/.freeze # rubocop:disable Metrics/LineLength
88

99
def version
1010
matches = VERSION_MATCHER.match(ua)

test/ua.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ IOS8: "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4
6666
IOS8_1_2: 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B440 Safari/600.1.4'
6767
IOS8_3: 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12F70 Safari/600.1.4'
6868
IOS9: "Mozilla/5.0 (iPad; CPU OS 9_0 like Mac OS X) AppleWebKit/601.1.17 (KHTML, like Gecko) Version/8.0 Mobile/13A175 Safari/600.1.4"
69+
IOS12: "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1"
6970
IOS_WEBVIEW: Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12H141
7071
IPAD: "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10"
7172
IPHONE: "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/1A542a Safari/419.3"

test/unit/ios_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ class IosTest < Minitest::Test
105105
refute browser.platform.mac?
106106
end
107107

108+
test "detects ios12" do
109+
browser = Browser.new(Browser["IOS12"])
110+
assert browser.platform.ios?
111+
assert browser.platform.ios?(12)
112+
refute browser.platform.mac?
113+
end
114+
108115
test "don't detect as two different versions" do
109116
browser = Browser.new(Browser["IOS8"])
110117
assert browser.platform.ios?(8)

0 commit comments

Comments
 (0)