user_agent_sanitizer 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/user_agent_sanitizer.rb +19 -2
- data/spec/user_agent_sanitizer_spec.rb +9 -3
- data/user_agent_sanitizer.gemspec +1 -1
- metadata +1 -1
data/lib/user_agent_sanitizer.rb
CHANGED
@@ -84,19 +84,36 @@ module UserAgentSanitizer
|
|
84
84
|
return "#{$1} #{$2}"
|
85
85
|
when /(Blackberry) ?(\d+)/i
|
86
86
|
return "#{$1} #{$2}"
|
87
|
+
when /Sensation(\w+)/i
|
88
|
+
@brand = "HTC"
|
89
|
+
@model = "Sensation #{$1.gsub("_", " ")}"
|
90
|
+
return nil
|
87
91
|
when /(HTC)[_\/]([a-z0-9]+)?/i
|
88
92
|
return [$1, $2].compact.join(" ")
|
89
93
|
when /(Samsung)[\/\-]([a-z0-9]+)([\/\-]([a-z0-9]+))?/i
|
90
94
|
return ['Samsung', $2, $4].compact.join(" ")
|
91
|
-
when /\((Linux; U; Android.*)\)/
|
92
|
-
return $1.split(";").last.split("/").first.gsub(/build/i, "").strip
|
93
95
|
when /(iPod|iPad)/
|
94
96
|
@brand = 'Apple'
|
95
97
|
@model = $1
|
96
98
|
return nil
|
99
|
+
when /PlayStation Portable/
|
100
|
+
@brand = 'Sony'
|
101
|
+
@model = 'PSP'
|
102
|
+
return nil
|
103
|
+
when /Opera Mobi/
|
104
|
+
@brand = 'Opera'
|
105
|
+
@model = 'Mobi'
|
106
|
+
return nil
|
97
107
|
when /(Windows NT \w+(\.\w+)+)/
|
98
108
|
@brand = "Microsoft"
|
99
109
|
@model = $1
|
110
|
+
return nil
|
111
|
+
when /(nokia);\s*([\w ]+)/i
|
112
|
+
@brand = $1.capitalize
|
113
|
+
@model = $2
|
114
|
+
return nil
|
115
|
+
when /\((Linux; U; Android.*)\)/
|
116
|
+
return $1.split(";").last.split("/").first.gsub(/build/i, "").strip
|
100
117
|
when /((#{BRANDS.join("|")}).*?)\//i
|
101
118
|
result=$1
|
102
119
|
|
@@ -4,7 +4,7 @@ require 'user_agent_sanitizer'
|
|
4
4
|
|
5
5
|
describe UserAgentSanitizer do
|
6
6
|
DEVICES = {
|
7
|
-
# Mobile
|
7
|
+
# Mobile devices
|
8
8
|
'BlackBerry8520/4.6.1.296 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/150' => ['BlackBerry', '8520'],
|
9
9
|
'BlackBerry8900/4.6.1.199 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/302' => ['BlackBerry', '8900'],
|
10
10
|
'HTC_Touch2_T3333 Opera/9.50 (Windows NT 5.1; U; nl)' => ['HTC','Touch2'],
|
@@ -14,7 +14,6 @@ describe UserAgentSanitizer do
|
|
14
14
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3' => ['Apple','iPhone'],
|
15
15
|
'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_5 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8L1 Safari/6533.18.5' => ['Apple','iPhone'],
|
16
16
|
'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; nl-nl) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/419.3' => ['Apple','iPhone'],
|
17
|
-
'Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5' => ['Apple','iPod'],
|
18
17
|
'Mozilla/5.0 (Linux; U; Android 1.5; en-gb; HTC Magic Build/CRB17) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1' => ['HTC','Magic'],
|
19
18
|
'Mozilla/5.0 (Linux; U; Android 1.5; nl-nl; GT-I5700 Build/CUPCAKE) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1' => ['Samsung','GT-I5700'],
|
20
19
|
'Mozilla/5.0 (Linux; U; Android 1.6; nl-nl; SonyEricssonX10i Build/R1FA016) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1' => ['SonyEricsson','X10i'],
|
@@ -38,9 +37,16 @@ describe UserAgentSanitizer do
|
|
38
37
|
'SAMSUNG-SGH-L600/L600ASGI3 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0' => ['Samsung','SGH L600'],
|
39
38
|
'SEC-SGHM620/1.0 Openwave/6.2.3 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0' => ['SEC','SGH M620'],
|
40
39
|
'SonyEricssonW995/R1FA Browser/NetFront/3.4 Profile/MIDP-2.1 Configuration/CLDC-1.1 JavaPlatform/JP-8.4.3' => ['SonyEricsson','W995'],
|
40
|
+
'(compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 800)' => ['Nokia','Lumia 800'],
|
41
|
+
'"Mozilla/5.0 (Linux; U; Android 4.0.3; nl-nl; SensationXE_Beats_Z715e Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"' => ['HTC','Sensation XE Beats Z715e'],
|
41
42
|
|
42
|
-
#
|
43
|
+
# Mobile browsers
|
44
|
+
'(Android 4.0.3; Linux; Opera Mobi/ADR-1205181138; U; nl) Presto/2.10.254 Version/12.00' => ['Opera', 'Mobi'],
|
45
|
+
|
46
|
+
# Tables and other handhelds
|
43
47
|
'(iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3' => ['Apple', 'iPad'],
|
48
|
+
'(PSP (PlayStation Portable); 2.00)' => ['Sony', 'PSP'],
|
49
|
+
'Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5' => ['Apple', 'iPod'],
|
44
50
|
|
45
51
|
# Desktop
|
46
52
|
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB0.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30618)' => ['Microsoft','Windows NT 6.0'],
|
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.name = 'user_agent_sanitizer'
|
4
4
|
s.summary = "Browser user agent sanitizer"
|
5
5
|
s.description = "Browser user agent sanitizer, with a focus on sanitizing mobile phone user agents to brand + model number"
|
6
|
-
s.version = '2.0.
|
6
|
+
s.version = '2.0.1'
|
7
7
|
s.date = '2012-07-11'
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Wes Oldenbeuving"]
|