useragent_parser 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/config/regexes.yaml +12 -5
- data/lib/useragent_parser/user_agent.rb +81 -26
- data/lib/useragent_parser/version.rb +1 -1
- data/spec/fixtures/test_referrers.yaml +3 -0
- data/spec/fixtures/test_user_agent_parser.yaml +6 -0
- data/spec/fixtures/test_user_agent_parser_os.yaml +8 -8
- data/spec/user_agent_spec.rb +16 -8
- metadata +1 -1
data/config/regexes.yaml
CHANGED
@@ -183,6 +183,10 @@ user_agent_parsers:
|
|
183
183
|
- regex: '(Outlook-Express)/(\d+)\.(\d+)'
|
184
184
|
family_replacement: 'Windows Live Mail'
|
185
185
|
|
186
|
+
# Android Mobile Safari
|
187
|
+
- regex: '(Version)\/(\d+)\.(\d+) Mobile Safari\/\d+'
|
188
|
+
family_replacement: 'Mobile Safari'
|
189
|
+
|
186
190
|
#### END SPECIAL CASES TOP ####
|
187
191
|
|
188
192
|
#### MAIN CASES - this catches > 50% of all browsers ####
|
@@ -403,19 +407,19 @@ os_parsers:
|
|
403
407
|
- regex: '(XBLWP7)'
|
404
408
|
os_replacement: 'Windows Phone OS'
|
405
409
|
|
406
|
-
- regex: '(Windows NT 6\.1)'
|
410
|
+
- regex: '(Windows NT) (6)\.(1)'
|
407
411
|
os_replacement: 'Windows 7'
|
408
412
|
|
409
|
-
- regex: '(Windows NT 6\.0)'
|
413
|
+
- regex: '(Windows NT) (6)\.(0)'
|
410
414
|
os_replacement: 'Windows Vista'
|
411
415
|
|
412
416
|
- regex: '(Windows 98|Windows XP|Windows ME|Windows 95|Windows CE|Windows 7|Windows NT 4\.0|Windows Vista|Windows 2000)'
|
413
417
|
|
414
418
|
# is this a spoof or is nt 6.2 out and about in some capacity?
|
415
|
-
- regex: '(Windows NT 6\.2)'
|
419
|
+
- regex: '(Windows NT) (6)\.(2)'
|
416
420
|
os_replacement: 'Windows 8'
|
417
421
|
|
418
|
-
- regex: '(Windows NT 5\.0)'
|
422
|
+
- regex: '(Windows NT) (5)\.(0)'
|
419
423
|
os_replacement: 'Windows 2000'
|
420
424
|
|
421
425
|
- regex: '(Windows Phone OS) (\d+)\.(\d+)'
|
@@ -423,7 +427,7 @@ os_parsers:
|
|
423
427
|
- regex: '(Windows ?Mobile)'
|
424
428
|
os_replacement: 'Windows Mobile'
|
425
429
|
|
426
|
-
- regex: '(
|
430
|
+
- regex: '(WinNT)(4)\.(0)'
|
427
431
|
os_replacement: 'Windows NT 4.0'
|
428
432
|
|
429
433
|
- regex: '(Win98)'
|
@@ -876,6 +880,9 @@ referrer_parsers:
|
|
876
880
|
- regex: '(mail\.yahoo\.net)'
|
877
881
|
referrer_replacement: 'Yahoo! Mail'
|
878
882
|
|
883
|
+
- regex: '(mm\.web\.de)'
|
884
|
+
referrer_replacement: 'WEB.DE'
|
885
|
+
|
879
886
|
- regex: '(email\.freenet\.de)'
|
880
887
|
referrer_replacement: 'WEB.DE'
|
881
888
|
|
@@ -46,14 +46,30 @@ module UseragentParser
|
|
46
46
|
@browser_version ||= "#{browser_major_version}.#{browser_minor_version}.#{browser_patch_version}".gsub(/\.+$/, '').strip
|
47
47
|
end
|
48
48
|
|
49
|
-
def os_version
|
50
|
-
@
|
49
|
+
def os_version(options = {})
|
50
|
+
return @os_family if os_platform == 'Windows'
|
51
|
+
if options.fetch(:minor_only, false)
|
52
|
+
@os_release ||= os_release
|
53
|
+
else
|
54
|
+
@os_version ||= "#{os_major_version}.#{os_minor_version}.#{os_patch_version}".gsub(/\.+$/, '').strip
|
55
|
+
end
|
51
56
|
end
|
52
57
|
|
53
58
|
def os
|
54
59
|
@os ||= os_name
|
55
60
|
end
|
56
61
|
|
62
|
+
def os_family
|
63
|
+
@os_platform ||= os_platform
|
64
|
+
end
|
65
|
+
|
66
|
+
def os_family_aggregated
|
67
|
+
case os_family
|
68
|
+
when 'Windows', 'Windows NT' then 'Windows'
|
69
|
+
else os_family
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
57
73
|
def browser
|
58
74
|
@browser ||= browser_name
|
59
75
|
end
|
@@ -131,7 +147,7 @@ module UseragentParser
|
|
131
147
|
return ios_mail_names if is_ios_mail?
|
132
148
|
return outlook_names if is_outlook?
|
133
149
|
return 'AOL Desktop' if @browser_family == 'AOL'
|
134
|
-
|
150
|
+
nil
|
135
151
|
end
|
136
152
|
|
137
153
|
def apple_mail_names
|
@@ -147,7 +163,16 @@ module UseragentParser
|
|
147
163
|
end
|
148
164
|
|
149
165
|
def ios_mail_names
|
150
|
-
|
166
|
+
prefix = "Apple Mobile Mail"
|
167
|
+
case @os_major_version
|
168
|
+
when '1' then "#{prefix} 1"
|
169
|
+
when '2' then "#{prefix} 2"
|
170
|
+
when '3' then "#{prefix} 3"
|
171
|
+
when '4' then "#{prefix} 4"
|
172
|
+
when '5' then "#{prefix} 5"
|
173
|
+
when '6' then "#{prefix} 6"
|
174
|
+
else "#{prefix}"
|
175
|
+
end
|
151
176
|
end
|
152
177
|
|
153
178
|
def outlook_names
|
@@ -165,6 +190,15 @@ module UseragentParser
|
|
165
190
|
end
|
166
191
|
|
167
192
|
def os_name
|
193
|
+
case os_platform
|
194
|
+
when 'Windows' then os_names_win_prefixed
|
195
|
+
when 'Windows NT' then os_names_winnt_prefixed
|
196
|
+
when 'Mac OS X' then os_names_osx_prefixed
|
197
|
+
else "#{os_family} #{os_version}".strip
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def os_name_unprefixed
|
168
202
|
case os_family
|
169
203
|
when 'Windows' then os_names_win
|
170
204
|
when 'Windows NT' then os_names_winnt
|
@@ -173,42 +207,63 @@ module UseragentParser
|
|
173
207
|
end
|
174
208
|
end
|
175
209
|
|
210
|
+
def os_platform
|
211
|
+
case @os_family
|
212
|
+
when 'Windows 98', 'Windows XP', 'Windows ME', 'Windows 95', 'Windows NT 4.0', 'Windows Vista', 'Windows 2000', 'Windows 7', 'Windows 8' then 'Windows'
|
213
|
+
else @os_family
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
176
217
|
def os_release
|
177
218
|
@release ||= "#{os_major_version}.#{os_minor_version}".gsub(/\.$/, '')
|
178
219
|
end
|
179
220
|
|
221
|
+
def os_names_win_prefixed
|
222
|
+
"Microsoft #{@os_family} #{os_release}"
|
223
|
+
end
|
224
|
+
|
180
225
|
def os_names_win
|
181
|
-
|
226
|
+
require 'pp'
|
227
|
+
pp self
|
228
|
+
pp 'HERE!'
|
229
|
+
|
230
|
+
os_version
|
231
|
+
end
|
232
|
+
|
233
|
+
def os_names_winnt_prefixed
|
234
|
+
"Microsoft Windows #{os_names_winnt}"
|
182
235
|
end
|
183
236
|
|
184
237
|
def os_names_winnt
|
185
|
-
prefix = "Microsoft Windows"
|
186
238
|
case os_release
|
187
|
-
when "3.1" then "
|
188
|
-
when "3.5" then "
|
189
|
-
when "4.0" then "
|
190
|
-
when "5.0" then "
|
191
|
-
when "5.1" then "
|
192
|
-
when "5.2" then "
|
193
|
-
when "6.0" then "
|
194
|
-
when "6.1" then "
|
195
|
-
when "6.2" then "
|
196
|
-
else "
|
239
|
+
when "3.1" then "NT 3.1"
|
240
|
+
when "3.5" then "NT 3.5"
|
241
|
+
when "4.0" then "NT 4.0"
|
242
|
+
when "5.0" then "2000"
|
243
|
+
when "5.1" then "XP"
|
244
|
+
when "5.2" then "XP 64bit / Server 2003"
|
245
|
+
when "6.0" then "Vista / Server 2008"
|
246
|
+
when "6.1" then "7 / Server 2008 R2"
|
247
|
+
when "6.2" then "8"
|
248
|
+
else "NT #{os_release}"
|
197
249
|
end
|
198
250
|
end
|
199
251
|
|
252
|
+
def os_names_osx_prefixed
|
253
|
+
"Apple Mac OS X #{os_version} (#{os_names_osx})"
|
254
|
+
end
|
255
|
+
|
200
256
|
def os_names_osx
|
201
|
-
prefix = "Apple Mac OS X"
|
202
257
|
case os_release
|
203
|
-
when "10.0" then "
|
204
|
-
when "10.1" then "
|
205
|
-
when "10.2" then "
|
206
|
-
when "10.3" then "
|
207
|
-
when "10.4" then "
|
208
|
-
when "10.5" then "
|
209
|
-
when "10.6" then "
|
210
|
-
when "10.7" then "
|
211
|
-
else "
|
258
|
+
when "10.0" then "Cheetah"
|
259
|
+
when "10.1" then "Puma"
|
260
|
+
when "10.2" then "Jaguar"
|
261
|
+
when "10.3" then "Panther"
|
262
|
+
when "10.4" then "Tiger"
|
263
|
+
when "10.5" then "Leopard"
|
264
|
+
when "10.6" then "Snow Leopard"
|
265
|
+
when "10.7" then "Lion"
|
266
|
+
else "Unknown"
|
212
267
|
end
|
213
268
|
end
|
214
269
|
end
|
@@ -388,3 +388,9 @@ test_cases:
|
|
388
388
|
minor: '0'
|
389
389
|
patch:
|
390
390
|
|
391
|
+
- user_agent_string: 'Mozilla/5.0 (Linux; U; Android 2.3.5; de-de; HTC Desire HD A9191 Build/GRJ90) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
|
392
|
+
family: 'Mobile Safari'
|
393
|
+
major: '4'
|
394
|
+
minor: '0'
|
395
|
+
patch:
|
396
|
+
|
@@ -30,8 +30,8 @@ test_cases:
|
|
30
30
|
|
31
31
|
- user_agent_string: 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 ThunderBrowse/3.3.5'
|
32
32
|
family: 'Windows 7'
|
33
|
-
major:
|
34
|
-
minor:
|
33
|
+
major: '6'
|
34
|
+
minor: '1'
|
35
35
|
patch:
|
36
36
|
patch_minor:
|
37
37
|
|
@@ -93,8 +93,8 @@ test_cases:
|
|
93
93
|
|
94
94
|
- user_agent_string: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) FireWeb/1.0.0.0'
|
95
95
|
family: 'Windows 7'
|
96
|
-
major:
|
97
|
-
minor:
|
96
|
+
major: '6'
|
97
|
+
minor: '1'
|
98
98
|
patch:
|
99
99
|
patch_minor:
|
100
100
|
|
@@ -227,8 +227,8 @@ test_cases:
|
|
227
227
|
|
228
228
|
- user_agent_string: 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.3a1) Gecko/20100208 MozillaDeveloperPreview/3.7a1 (.NET CLR 3.5.30729)'
|
229
229
|
family: 'Windows 7'
|
230
|
-
major:
|
231
|
-
minor:
|
230
|
+
major: '6'
|
231
|
+
minor: '1'
|
232
232
|
patch:
|
233
233
|
patch_minor:
|
234
234
|
|
@@ -315,8 +315,8 @@ test_cases:
|
|
315
315
|
- user_agent_string: 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; chromeframe; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729)'
|
316
316
|
js_ua: "{'js_user_agent_string': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.1 (KHTML, like Gecko) Chrome/2.0.169.1 Safari/530.1'}"
|
317
317
|
family: 'Windows Vista'
|
318
|
-
major:
|
319
|
-
minor:
|
318
|
+
major: '6'
|
319
|
+
minor: '0'
|
320
320
|
patch:
|
321
321
|
patch_minor:
|
322
322
|
|
data/spec/user_agent_spec.rb
CHANGED
@@ -144,26 +144,34 @@ describe UseragentParser::UserAgent do
|
|
144
144
|
end
|
145
145
|
|
146
146
|
describe "Apple Mobile Mail" do
|
147
|
-
it "should recognize
|
148
|
-
UseragentParser.parse_with_referrer('Mozilla/5.0 (
|
147
|
+
it "should recognize iOS 2" do
|
148
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_1 like Mac OS X; de-de) AppleWebKit/525.18.1 (KHTML, like Gecko)').email_version.should == 'Apple Mobile Mail 2'
|
149
149
|
end
|
150
150
|
|
151
|
-
it "should recognize
|
152
|
-
UseragentParser.parse_with_referrer('Mozilla/5.0 (
|
151
|
+
it "should recognize iOS 3" do
|
152
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_3 like Mac OS X; de-de) AppleWebKit/528.18 (KHTML, like Gecko)').email_version.should == 'Apple Mobile Mail 3'
|
153
153
|
end
|
154
154
|
|
155
|
-
it "should recognize
|
156
|
-
UseragentParser.parse_with_referrer('Mozilla/5.0 (iPhone; U; CPU iPhone OS
|
155
|
+
it "should recognize iOS 4" do
|
156
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; de-de) AppleWebKit/533.17.9 (KHTML, like Gecko)').email_version.should == 'Apple Mobile Mail 4'
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should recognize iOS 5" do
|
160
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko)').email_version.should == 'Apple Mobile Mail 5'
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should recognize iOS 2" do
|
164
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/535.8 (KHTML, like Gecko)').email_version.should == 'Apple Mobile Mail 6'
|
157
165
|
end
|
158
166
|
|
159
167
|
it "should not mistake Mobile Safari for Apple Mail" do
|
160
|
-
|
168
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/535.8 (KHTML, like Gecko)', 'http://example.com').email_version.should be_nil
|
161
169
|
end
|
162
170
|
end
|
163
171
|
|
164
172
|
describe "AOL" do
|
165
173
|
it "should recognize the Webmail interface" do
|
166
|
-
UseragentParser.parse_with_referrer('Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.13) Gecko/20101203 AskTbFXTV5/3.9.1.14019 Firefox/3.6.13', 'http://mail.aol.com/33222-111/aol-1/de-de/Lite/MsgRead.aspx?folder=Spam&uid=1.28305313&seq=0&searchIn=none&searchQuery=&start=0&sort=received').
|
174
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.13) Gecko/20101203 AskTbFXTV5/3.9.1.14019 Firefox/3.6.13', 'http://mail.aol.com/33222-111/aol-1/de-de/Lite/MsgRead.aspx?folder=Spam&uid=1.28305313&seq=0&searchIn=none&searchQuery=&start=0&sort=received').email.should == 'AOL Webmail'
|
167
175
|
end
|
168
176
|
end
|
169
177
|
end
|