diff --git a/CHANGELOG.md b/CHANGELOG.md index 6143df90..7cdab03b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +- Add `Browser::Base#epiphany?`. +- Don't ever match linux-based browsers as Safari. + ## 6.1.0 - Add more bots (mostly related to AI crawlers) diff --git a/README.md b/README.md index b35aeeef..d62fc00e 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ browser.qq? browser.weibo? browser.sputnik? browser.sougou_browser? +browser.epiphany? # Get bot info browser.bot.name diff --git a/lib/browser/base.rb b/lib/browser/base.rb index 4c974c93..b6c551df 100644 --- a/lib/browser/base.rb +++ b/lib/browser/base.rb @@ -268,6 +268,11 @@ def electron?(expected_version = nil) instance_of?(Electron) && detect_version?(full_version, expected_version) end + # Detect if the browser is Epiphany. + def epiphany?(expected_version = nil) + instance_of?(Epiphany) && detect_version?(full_version, expected_version) + end + private def validate_size(subject, input) actual_bytesize = input.bytesize size_limit = Browser.public_send(:"#{subject}_size_limit") diff --git a/lib/browser/browser.rb b/lib/browser/browser.rb index adb84274..1ea4d442 100644 --- a/lib/browser/browser.rb +++ b/lib/browser/browser.rb @@ -37,6 +37,7 @@ require_relative "maxthon" require_relative "sougou_browser" require_relative "google_search_app" +require_relative "epiphany" require_relative "bot" require_relative "bot/empty_user_agent_matcher" @@ -77,23 +78,26 @@ def self.matchers InternetExplorer, Firefox, Otter, - Facebook, # must be placed before Chrome and Safari - Instagram, # must be placed before Chrome and Safari - Snapchat, # must be placed before Chrome and Safari - Weibo, # must be placed before Chrome and Safari - MicroMessenger, # must be placed before QQ - QQ, # must be placed before Chrome and Safari - Alipay, # must be placed before Chrome and Safari - Electron, # must be placed before Chrome and Safari - Yandex, # must be placed before Chrome and Safari - Sputnik, # must be placed before Chrome and Safari - DuckDuckGo, # must be placed before Chrome and Safari - SamsungBrowser, # must be placed before Chrome and Safari - HuaweiBrowser, # must be placed before Chrome and Safari - MiuiBrowser, # must be placed before Chrome and Safari - Maxthon, # must be placed before Chrome and Safari - SougouBrowser, # must be placed before Chrome and Safari - GoogleSearchApp, # must be placed before Chrome and Safari + Epiphany, + Facebook, + Instagram, + Snapchat, + Weibo, + MicroMessenger, # must be placed before QQ + QQ, + Alipay, + Electron, + Yandex, + Sputnik, + DuckDuckGo, + SamsungBrowser, + HuaweiBrowser, + MiuiBrowser, + Maxthon, + SougouBrowser, + GoogleSearchApp, + + # Must be last Chrome, Safari, Unknown diff --git a/lib/browser/epiphany.rb b/lib/browser/epiphany.rb new file mode 100644 index 00000000..4806bf36 --- /dev/null +++ b/lib/browser/epiphany.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Browser + class Epiphany < Base + def id + :epiphany + end + + def name + "Epiphany" + end + + def full_version + ua[%r{Epiphany/([\d.]+)}, 1] || "0.0" + end + + def match? + ua.include?("Epiphany") + end + end +end diff --git a/lib/browser/safari.rb b/lib/browser/safari.rb index ee15c1e7..d3118019 100644 --- a/lib/browser/safari.rb +++ b/lib/browser/safari.rb @@ -19,6 +19,7 @@ def full_version def match? ua.include?("Safari") && + !platform.linux? && !ua.match?(/PhantomJS|FxiOS/) && !edge? && !chrome? && diff --git a/test/ua.yml b/test/ua.yml index 39397790..db88221c 100644 --- a/test/ua.yml +++ b/test/ua.yml @@ -36,6 +36,7 @@ CUSTOM_APP: "Our App 0.0.1 (Linux; Android 4.0.3; HTC Ruby Build/IML74K; en_CA)" DUCKDUCKGO_BROWSER_ANDROID: Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36 DuckDuckGo/5" DUCKDUCKGO_BROWSER_IOS: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 DuckDuckGo/7" ELECTRON: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Electron/1.4.12 Safari/537.36" +EPIPHANY: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Safari/605.1.15 Ubuntu/16.04 (3.18.11-0ubuntu1) Epiphany/3.18.11" FACEBOOK: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 [FBAN/FBIOS;FBAV/135.0.0.45.90;FBBV/66877072;FBDV/iPhone9,3;FBMD/iPhone;FBSN/iOS;FBSV/10.3.3;FBSS/2;FBCR/AT&T;FBID/phone;FBLC/en_US;FBOP/5;FBRV/0] FACEBOOK_ANDROID: "Mozilla/5.0 (Linux; Android 9; ONEPLUS A6003 Build/PKQ1.180716.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/73.0.3683.90 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/214.0.0.43.83;]" FACEBOOK_IOS: "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 [FBAN/FBIOS;FBDV/iPhone11,2;FBMD/iPhone;FBSN/iOS;FBSV/12.1.4;FBSS/3;FBCR/KPN NL;FBID/phone;FBLC/en_GB;FBOP/5]" diff --git a/test/unit/epiphany_test.rb b/test/unit/epiphany_test.rb new file mode 100644 index 00000000..73b15f7e --- /dev/null +++ b/test/unit/epiphany_test.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require "test_helper" + +class EpiphanyBrowserTest < Minitest::Test + test "detects epiphany browser" do + browser = Browser.new(Browser["EPIPHANY"]) + + assert browser.epiphany? + refute browser.safari? + assert_equal "Epiphany", browser.name + assert_equal :epiphany, browser.id + assert_equal "3.18.11", browser.full_version + assert_equal "3", browser.version + end + + test "detects version by range" do + browser = Browser.new(Browser["EPIPHANY"]) + assert browser.epiphany?(%w[=3.18.11]) + end +end