Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/user_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def self.parse(string)

agents = Browsers::Base.new
while m = string.to_s.match(MATCHER)
agents << new(m[1], m[2], m[4])
agents << new(m[1], m[2], m[4], string.to_s)
string = string[m[0].length..-1].strip
end
Browsers.extend(agents)
end

attr_reader :product, :version, :comment
attr_reader :product, :version, :comment, :all

def initialize(product, version = nil, comment = nil)
def initialize(product, version = nil, comment = nil, all = nil)
if product
@product = product
else
Expand All @@ -47,6 +47,8 @@ def initialize(product, version = nil, comment = nil)
else
@comment = comment
end

@all = all
end

include Comparable
Expand Down
2 changes: 2 additions & 0 deletions lib/user_agent/browsers/webkit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def browser
'Android'
elsif platform == 'BlackBerry'
platform
elsif application.all =~ /UCBrowser/
'UCBrowser'
else
'Safari'
end
Expand Down
32 changes: 32 additions & 0 deletions spec/browsers/webkit_user_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1241,3 +1241,35 @@

it { expect(@useragent).to be_mobile }
end

describe 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_1_2 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/17A860 UCBrowser/12.6.6.1230 Mobile AliApp(TUnionSDK/0.1.20.3)' do
before do
@useragent = UserAgent.parse('Mozilla/5.0 (iPhone; CPU iPhone OS 13_1_2 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/17A860 UCBrowser/12.6.6.1230 Mobile AliApp(TUnionSDK/0.1.20.3)')
end

it "should return 'UCBrowser' as its browser" do
expect(@useragent.browser).to eq('UCBrowser')
end

it 'should return :strong as its security' do
expect(@useragent.security).to be(nil)
end

it "should return '537.51.1' as its build" do
expect(@useragent.build).to eq('537.51.1')
end

it "should return '537.51.1' as its webkit version" do
expect(@useragent.webkit.version).to eq('537.51.1')
end

it "should return 'iPhone' as its platform" do
expect(@useragent.platform).to eq('iPhone')
end

it "should return 'iOS 13.1.2' as its os" do
expect(@useragent.os).to eq('iOS 13.1.2')
end

it { expect(@useragent).to be_mobile }
end