Skip to content

Commit

Permalink
Merge branch 'master' into android-device-names
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando authored Nov 16, 2019
2 parents 3b15c9f + 405d378 commit 29cdf93
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Improve Yandex detection.
- Add Sputnik (https://browser.sputnik.ru)
- Detect Android devices.
- Add ScoutURLMonitor to the bot list.

## 2.6.1

Expand Down
1 change: 1 addition & 0 deletions bots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ relateiq: "RelateIQ"
riddler: "Riddler Bot"
rogerbot: "SeoMoz spider"
rssmicro: "RSS/Atom Feed Robot (rssmicro.com)"
scouturlmonitor: "ScoutURLMonitor"
scrapy: "Scrapy"
screaming frog seo spider: Screaming Frog SEO Spider
searchmetricsbot: "SearchmetricsBot"
Expand Down
16 changes: 14 additions & 2 deletions lib/browser/platform/ios.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@ module Browser
class Platform
class IOS < Base
MATCHER = /(iPhone|iPad|iPod)/.freeze
VERSION_MATCHER = /OS ([\d.]+)/.freeze
VERSION_MATCHER = /OS ((?<major>\d)_(?<minor>\d)_?(?<patch>\d)?)/.freeze

def version
ua[VERSION_MATCHER, 1] || "0"
matches = VERSION_MATCHER.match(ua)

return "0" unless matches

versions = [matches[:major]]

if matches[:patch]
versions.push(matches[:minor], matches[:patch])
else
versions.push(matches[:minor]) unless matches[:minor] == "0"
end

versions.join(".")
end

def name
Expand Down
2 changes: 2 additions & 0 deletions test/ua.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ IOS5: "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46
IOS6: "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
IOS7: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53"
IOS8: "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A365 Safari/600.1.4"
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'
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'
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"
IOS_WEBVIEW: Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12H141
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"
Expand Down
2 changes: 2 additions & 0 deletions test/ua_bots.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
ADLXBOT: "Mozilla/5.0 (compatible; adidxbot/2.0; +http://www.bing.com/bingbot.htm)"
ADS_TXT_CRAWLER: "AdsTxtCrawler/1.0"
ANDERSPINK: "Mozilla/5.0 (compatible; AndersPinkBot/1.0; +http://anderspink.com/bot.html)"
Expand Down Expand Up @@ -61,6 +62,7 @@ PROXIMIC: "Mozilla/5.0 (compatible; proximic; +http://www.proximic.com/info/spid
PUINCRAWLER: "Pu_iN Crawler (+http://semanticjuice.com/)"
QUERYSEEKER: "QuerySeekerSpider ( http://queryseeker.com/bot.html )"
QUICKCRAWLER: "Quick-Crawler (+https://www.scrapinghub.com/)"
SCOUT_URL_MONITOR: ScoutURLMonitor/6.2.2
SCRAPY: "Scrapy/0.18.4 (+http://scrapy.org)"
SEMANTICBOT: "Mozilla/5.0 (compatible; Semanticbot/1.0; +http://sempi.tech/bot.html)"
SEO_AUDIT: "Mozilla/5.0 (compatible; seo-audit-check-bot/1.0)"
Expand Down
21 changes: 21 additions & 0 deletions test/unit/platform_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ def id
assert_equal "9", platform.version
end

test "detect specific minor iOS (iPhone)" do
platform = Browser::Platform.new(Browser["IOS8_3"])

assert_equal "iOS (iPhone)", platform.name
assert_equal :ios, platform.id
assert platform.ios?
assert platform.ios?(8.3)
assert_equal "8.3", platform.version
end

test "detect specific patch iOS (iPhone)" do
platform = Browser::Platform.new(Browser["IOS8_1_2"])

assert_equal "iOS (iPhone)", platform.name
assert_equal :ios, platform.id
assert platform.ios?
assert platform.ios?("8.1.2")
assert platform.ios?("<8.2")
assert_equal "8.1.2", platform.version
end

test "detect ios (iPod Touch)" do
platform = Browser::Platform.new(Browser["IPOD"])

Expand Down

0 comments on commit 29cdf93

Please sign in to comment.