browser 5.0.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78fd9a10d5ca6461be5395616edcc1456967a595363f027548bf8a9fa0bfdf10
4
- data.tar.gz: 599be9a3080333b44234ecf4c7ec21572e81e5dc3d04fccfa66a631bc6897494
3
+ metadata.gz: 4e5b6ed4dfb725a6d4814c3bd7a0a3897c0fe4fdeb9679d048cbb42123d6117c
4
+ data.tar.gz: b053a5fcf79d5fbea19849bde05125598563ac1b754dcd661f8c9fb96df2f3d4
5
5
  SHA512:
6
- metadata.gz: ca6e173a47d2d1489816eb4794c57abc4fc3ff6f1ae63826570c71213e1177813895595240c995704ff50d22666ddae78900ac8eeea77cff93f3f63397bf4d7a
7
- data.tar.gz: a09fe431f93c0dc9dd24ae2b1679538c4f61586b8334458adb41e6475c50da5850a747e1630b3904be57ccc360bc12333632cf1986978417e690aca4f8747356
6
+ metadata.gz: 9ea11931654143308193198a53edf5009dd301e04610e736c7da191c16c3578dd96df95213c787591f916859f604e01a61ef6baf12744a5ad84499dcaf93bf57
7
+ data.tar.gz: 7983885eca85b9cf2812f37b291020b2a8ef9ba3a7ee1a44f2a28e643fb786e6565d2a9394f57728c0444d82dc0ca7655eb6568b12578d9e50d8d191d7ca20c9
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.1.0
4
+
5
+ - Add Samsung device detection.
6
+ - Delay parsing `Accept-Language` until `Browser::Base#accept_language` is
7
+ called for the first time.
8
+ - Bump up default size limit for `Accept-Language` and `User-Agent` to 2048
9
+ bytes.
10
+
3
11
  ## 5.0.0
4
12
 
5
13
  - Rename `Browser::Platform#other?` to `Browser::Platform#unknown?`.
@@ -18,7 +26,7 @@
18
26
  - Fix QQ detection.
19
27
  - Fix Alipay detection.
20
28
  - Add Sougou Browser detection.
21
- - User agent has a size limit of 512 bytes. This can be customized through
29
+ - User agent has a size limit of 512 bytes. This can be customized through
22
30
  `Browser.user_agent_size_limit`.
23
31
  - Accept-Language has a size limit of 256 bytes. This can be customized through
24
32
  `Browser.accept_language_size_limit`.
data/README.md CHANGED
@@ -90,6 +90,7 @@ browser.device.tv?
90
90
  browser.device.vita?
91
91
  browser.device.wii?
92
92
  browser.device.wiiu?
93
+ browser.device.samsung?
93
94
  browser.device.switch?
94
95
  browser.device.xbox?
95
96
  browser.device.xbox_360?
@@ -352,16 +353,16 @@ end
352
353
 
353
354
  ### Restrictions
354
355
 
355
- - User agent has a size limit of 512 bytes. This can be customized through
356
+ - User agent has a size limit of 2048 bytes. This can be customized through
356
357
  `Browser.user_agent_size_limit=(size)`.
357
- - Accept-Language has a size limit of 256 bytes. This can be customized through
358
+ - Accept-Language has a size limit of 2048 bytes. This can be customized through
358
359
  `Browser.accept_language_size_limit=(size)`.
359
360
 
360
361
  If size is not respected, then `Browser::Error` is raised.
361
362
 
362
363
  ```ruby
363
- Browser.user_agent_size_limit = 1024
364
- Browser.accept_language_size_limit = 150
364
+ Browser.user_agent_size_limit = 4096
365
+ Browser.accept_language_size_limit = 4096
365
366
  ```
366
367
 
367
368
  ## Development
@@ -6,15 +6,11 @@ module Browser
6
6
 
7
7
  attr_reader :ua
8
8
 
9
- # Return an array with all preferred languages that this browser accepts.
10
- attr_reader :accept_language
11
-
12
9
  def initialize(ua, accept_language: nil)
13
10
  validate_size(:user_agent, ua.to_s)
14
- validate_size(:accept_language, accept_language.to_s)
15
11
 
16
12
  @ua = ua
17
- @accept_language = AcceptLanguage.parse(accept_language)
13
+ @accept_language_raw = accept_language.to_s
18
14
  end
19
15
 
20
16
  # Return a meta info about this browser.
@@ -22,6 +18,14 @@ module Browser
22
18
  Meta.get(self)
23
19
  end
24
20
 
21
+ # Return an array with all preferred languages that this browser accepts.
22
+ def accept_language
23
+ @accept_language ||= begin
24
+ validate_size(:accept_language, @accept_language_raw)
25
+ AcceptLanguage.parse(@accept_language_raw)
26
+ end
27
+ end
28
+
25
29
  alias_method :to_a, :meta
26
30
 
27
31
  # Return meta representation as string.
@@ -263,7 +267,7 @@ module Browser
263
267
 
264
268
  raise Error,
265
269
  "#{subject} cannot be larger than #{size_limit} bytes; " \
266
- "actual size is #{actual_bytesize}"
270
+ "actual size is #{actual_bytesize} bytes"
267
271
  end
268
272
  end
269
273
  end
@@ -62,8 +62,8 @@ module Browser
62
62
  attr_accessor :accept_language_size_limit
63
63
  end
64
64
 
65
- self.user_agent_size_limit = 512
66
- self.accept_language_size_limit = 256
65
+ self.user_agent_size_limit = 2048
66
+ self.accept_language_size_limit = 2048
67
67
 
68
68
  # Hold the list of browser matchers.
69
69
  # Order is important.
@@ -20,6 +20,7 @@ require_relative "device/switch"
20
20
  require_relative "device/tv"
21
21
  require_relative "device/xbox_one"
22
22
  require_relative "device/xbox_360"
23
+ require_relative "device/samsung"
23
24
 
24
25
  module Browser
25
26
  class Device
@@ -29,6 +30,7 @@ module Browser
29
30
  # Order is important.
30
31
  def self.matchers
31
32
  @matchers ||= [
33
+ Samsung,
32
34
  XboxOne,
33
35
  Xbox360,
34
36
  Surface,
@@ -191,6 +193,11 @@ module Browser
191
193
  xbox? || playstation? || nintendo?
192
194
  end
193
195
 
196
+ # Detect if device is a Samsung.
197
+ def samsung?
198
+ id == :samsung
199
+ end
200
+
194
201
  # Regex taken from http://detectmobilebrowsers.com
195
202
  # rubocop:disable Layout/LineLength
196
203
  private def detect_mobile?
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Browser
4
+ class Device
5
+ class Samsung < Base
6
+ REGEX = /\(Linux.*?; Android.*?; (SAMSUNG )?(SM-[A-Z0-9]+).*?\)/i.freeze
7
+
8
+ def self.names
9
+ @names ||= YAML.load_file(Browser.root.join("samsung.yml").to_s)
10
+ end
11
+
12
+ def id
13
+ :samsung
14
+ end
15
+
16
+ def name
17
+ "Samsung #{self.class.names[code] || code}"
18
+ end
19
+
20
+ def code
21
+ matches && matches[2]
22
+ end
23
+
24
+ def matches
25
+ @matches ||= ua.match(REGEX)
26
+ end
27
+
28
+ def match?
29
+ !!matches
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Browser
4
- VERSION = "5.0.0"
4
+ VERSION = "5.1.0"
5
5
  end
@@ -0,0 +1,138 @@
1
+ # Source: https://en.wikipedia.org/wiki/Samsung_Galaxy
2
+ SM-G900H: Galaxy S5 Exynos
3
+ SM-A320FL: Galaxy A3
4
+ SM-G780F: Galaxy S20 Fan Edition
5
+ SM-G781B: Galaxy S20 Fan Edition
6
+ SM-F196B: Galaxy Z Fold2 5G
7
+ SM-G928A: Galaxy S6 Edge+
8
+ SM-G928AZ: Galaxy S6 Edge+
9
+ SM-G928D: Galaxy S6 Edge+
10
+ SM-G928F: Galaxy S6 Edge+
11
+ SM-G928FD: Galaxy S6 Edge+
12
+ SM-G928I: Galaxy S6 Edge+
13
+ SM-G928K: Galaxy S6 Edge+
14
+ SM-G928L: Galaxy S6 Edge+
15
+ SM-G928P: Galaxy S6 Edge+
16
+ SM-G928PZ: Galaxy S6 Edge+
17
+ SM-G928R4: Galaxy S6 Edge+
18
+ SM-G928R7: Galaxy S6 Edge+
19
+ SM-G928S: Galaxy S6 Edge+
20
+ SM-G928T: Galaxy S6 Edge+
21
+ SM-G928T1: Galaxy S6 Edge+
22
+ SM-G928TR: Galaxy S6 Edge+
23
+ SM-G928V: Galaxy S6 Edge+
24
+ SM-G9280: Galaxy S6 Edge+
25
+ SM-G9288: Galaxy S6 Edge+
26
+ SM-G9289: Galaxy S6 Edge+
27
+ SM-A8000: Galaxy A8
28
+ SM-A800F: Galaxy A8
29
+ SM-A800I: Galaxy A8
30
+ SM-A800S: Galaxy A8
31
+ SM-A800Y: Galaxy A8
32
+ SM-N9200: Galaxy Note 5
33
+ SM-N920C: Galaxy Note 5
34
+ SM-N920T: Galaxy Note 5
35
+ SM-N920A: Galaxy Note 5
36
+ SM-N920I: Galaxy Note 5
37
+ SM-N9208: Galaxy Note 5
38
+ SM-G903FP: Galaxy S5 Neo
39
+ SM-G903WP: Galaxy S5 Neo
40
+ SM-G925A: Galaxy S6 Edge
41
+ SM-G925AZ: Galaxy S6 Edge
42
+ SM-G925F: Galaxy S6 Edge
43
+ SM-G925I: Galaxy S6 Edge
44
+ SM-G925K: Galaxy S6 Edge
45
+ SM-G925L: Galaxy S6 Edge
46
+ SM-G925P: Galaxy S6 Edge
47
+ SM-G925PZ: Galaxy S6 Edge
48
+ SM-G925R4: Galaxy S6 Edge
49
+ SM-G925R7: Galaxy S6 Edge
50
+ SM-G925S: Galaxy S6 Edge
51
+ SM-G925T: Galaxy S6 Edge
52
+ SM-G925T1: Galaxy S6 Edge
53
+ SM-G925TR: Galaxy S6 Edge
54
+ SM-G925V: Galaxy S6 Edge
55
+ SM-G9250: Galaxy S6 Edge
56
+ SM-G9258: Galaxy S6 Edge
57
+ SM-G9259: Galaxy S6 Edge
58
+ SM-G920A: Galaxy S6
59
+ SM-G920AZ: Galaxy S6
60
+ SM-G920D: Galaxy S6
61
+ SM-G920F: Galaxy S6
62
+ SM-G920FD: Galaxy S6
63
+ SM-G920I: Galaxy S6
64
+ SM-G920K: Galaxy S6
65
+ SM-G920L: Galaxy S6
66
+ SM-G920P: Galaxy S6
67
+ SM-G920PZ: Galaxy S6
68
+ SM-G920R4: Galaxy S6
69
+ SM-G920R7: Galaxy S6
70
+ SM-G920S: Galaxy S6
71
+ SM-G920T: Galaxy S6
72
+ SM-G920T1: Galaxy S6
73
+ SM-G920TR: Galaxy S6
74
+ SM-G920V: Galaxy S6
75
+ SM-G9200: Galaxy S6
76
+ SM-G9208: Galaxy S6
77
+ SM-G9209: Galaxy S6
78
+ SM-A700F: Galaxy A7
79
+ SM-A700FD: Galaxy A7
80
+ SM-A700FQ: Galaxy A7
81
+ SM-A700H: Galaxy A7
82
+ SM-A700K: Galaxy A7
83
+ SM-A700L: Galaxy A7
84
+ SM-A700M: Galaxy A7
85
+ SM-A700S: Galaxy A7
86
+ SM-A700X: Galaxy A7
87
+ SM-A700YD: Galaxy A7
88
+ SM-A700YZ: Galaxy A7
89
+ SM-A7000: Galaxy A7
90
+ SM-A7009: Galaxy A7
91
+ SM-A7009W: Galaxy A7
92
+ SM-G530BT: Galaxy Grand Prime
93
+ SM-G530F: Galaxy Grand Prime
94
+ SM-G530FQ: Galaxy Grand Prime
95
+ SM-G530FZ: Galaxy Grand Prime
96
+ SM-G530H: Galaxy Grand Prime
97
+ SM-G530M: Galaxy Grand Prime
98
+ SM-G530MU: Galaxy Grand Prime
99
+ SM-G530P: Galaxy Grand Prime
100
+ SM-G530R4: Galaxy Grand Prime
101
+ SM-G530R7: Galaxy Grand Prime
102
+ SM-G530T: Galaxy Grand Prime
103
+ SM-G530W: Galaxy Grand Prime
104
+ SM-G530Y: Galaxy Grand Prime
105
+ SM-G5306W: Galaxy Grand Prime
106
+ SM-G5308W: Galaxy Grand Prime
107
+ SM-G5309W: Galaxy Grand Prime
108
+ SM-J7109: Galaxy J7
109
+ SM-J710F: Galaxy J7
110
+ SM-J710FN: Galaxy J7
111
+ SM-J710H: Galaxy J7
112
+ SM-J710MN: Galaxy J7
113
+ SM-J710FQ: Galaxy J7
114
+ SM-J710K: Galaxy J7
115
+ SM-J710K: Galaxy J7
116
+ SM-J710GN: Galaxy J7
117
+ SM-J5109: Galaxy J5
118
+ SM-J510F: Galaxy J5
119
+ SM-J510FN: Galaxy J5
120
+ SM-J510H: Galaxy J5
121
+ SM-J510G: Galaxy J5
122
+ SM-J510MN: Galaxy J5
123
+ SM-J510Y: Galaxy J5
124
+ SM-J5108: Galaxy J5
125
+ SM-J510K: Galaxy J5
126
+ SM-J510L: Galaxy J5
127
+ SM-J510S: Galaxy J5
128
+ SM-J510UN: Galaxy J5
129
+ SM-G570F: Galaxy J2 Prime
130
+ SM-G570M: Galaxy J2 Prime
131
+ SM-G532F: Galaxy J2 Prime
132
+ SM-G532M: Galaxy J2 Prime
133
+ SM-G532G: Galaxy J2 Prime
134
+ SM-G610F: Galaxy J7 Prime
135
+ SM-G610M: Galaxy J7 Prime
136
+ SM-G975F: Galaxy S10+
137
+ SM-G960F: Galaxy S9
138
+ SM-F700F: Galaxy Z Flip
@@ -155,21 +155,35 @@ class BrowserTest < Minitest::Test
155
155
  refute browser.known?
156
156
  end
157
157
 
158
- test "rejects user agent larger than 512 bytes" do
159
- message = "user_agent cannot be larger than 512 bytes; actual size is " \
160
- "513 bytes"
161
-
162
- assert_raises(Browser::Error, message) do
163
- Browser.new("a" * 513)
164
- end
165
- end
166
-
167
- test "rejects accept language larger than 256 bytes" do
168
- message = "accept_language cannot be larger than 256 bytes; actual size " \
169
- "is 257 bytes"
170
-
171
- assert_raises(Browser::Error, message) do
172
- Browser.new("Chrome", accept_language: "a" * 257)
173
- end
158
+ test "rejects user agent larger than 2048 bytes" do
159
+ message = "user_agent cannot be larger than 2048 bytes; actual size is " \
160
+ "2049 bytes"
161
+
162
+ error =
163
+ begin
164
+ Browser.new("a" * 2049)
165
+ nil
166
+ rescue Browser::Error => error
167
+ error
168
+ end
169
+
170
+ refute_nil error
171
+ assert_equal message, error.message
172
+ end
173
+
174
+ test "rejects accept language larger than 2048 bytes" do
175
+ message = "accept_language cannot be larger than 2048 bytes; actual size " \
176
+ "is 2049 bytes"
177
+
178
+ error =
179
+ begin
180
+ Browser.new("Chrome", accept_language: "a" * 2049).accept_language
181
+ nil
182
+ rescue Browser::Error => error
183
+ error
184
+ end
185
+
186
+ refute_nil error
187
+ assert_equal message, error.message
174
188
  end
175
189
  end
@@ -136,6 +136,10 @@ SAFARI_IPHONE_WEBAPP_MODE: "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac O
136
136
  SAMSUNG: "Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; SAMSUNG-SGH-I497 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30"
137
137
  SAMSUNG_BROWSER: "Mozilla/5.0 (Linux; Android 10; SAMSUNG SM-N960U) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/11.1 Chrome/75.0.3770.143 Mobile Safari/537.36"
138
138
  SAMSUNG_CHROME: "Mozilla/5.0 (Linux; Android 4.4.2; en-gb; SAMSUNG GT-I9195/I9195XXUCNEA Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36"
139
+ SAMSUNG_SM-G975F: "Mozilla/5.0 (Linux; Android 10; SM-G975F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.101 Mobile Safari/537.36"
140
+ SAMSUNG_SM-G960F: "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.127 Mobile Safari/537.36"
141
+ SAMSUNG_SM-F700F: "Mozilla/5.0 (Linux; Android 10; SAMSUNG SM-F700F) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/11.1 Chrome/75.0.3770.143 Mobile Safari/537.36"
142
+ SAMSUNG_SM-FAKE: "Mozilla/5.0 (Linux; Android 8.0.0; SM-0000) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.127 Mobile Safari/537.36"
139
143
  SMART_TV: "Mozilla/5.0 (SmartHub; SMART-TV; U; Linux/SmartTV) AppleWebKit/531.2+ (KHTML, like Gecko) WebBrowser/1.0 SmartTV Safari/531.2+"
140
144
  SNAPCHAT: Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Snapchat/10.69.5.72 (iPhone10,3; iOS 13.2.2; gzip)
141
145
  SNAPCHAT_EMPTY_STRING_VERSION: "Mozilla/5.0 (Linux; Android 9; SM-N960U Build/PPR1.180610.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36Snapchat10.70.0.0 (SM-N960U; Android 9#N960USQS3CSJ2#28; gzip)"
@@ -258,4 +258,31 @@ class DeviceTest < Minitest::Test
258
258
  assert_equal name, device.name
259
259
  end
260
260
  end
261
+
262
+ test "detect samsung devices" do
263
+ device = Browser::Device.new(Browser["SAMSUNG_SM-G975F"])
264
+
265
+ assert device.samsung?
266
+ assert_equal :samsung, device.id
267
+ assert_equal "Samsung Galaxy S10+", device.name
268
+ end
269
+
270
+ test "detect generic samsung devices" do
271
+ device = Browser::Device.new(Browser["SAMSUNG_SM-FAKE"])
272
+
273
+ assert device.samsung?
274
+ assert_equal :samsung, device.id
275
+ assert_equal "Samsung SM-0000", device.name
276
+ end
277
+
278
+ {
279
+ "SAMSUNG_SM-G975F" => "Samsung Galaxy S10+",
280
+ "SAMSUNG_SM-G960F" => "Samsung Galaxy S9",
281
+ "SAMSUNG_SM-F700F" => "Samsung Galaxy Z Flip"
282
+ }.each do |key, name|
283
+ test "detect device name of #{key} as #{name}" do
284
+ device = Browser::Device.new(Browser[key])
285
+ assert_equal name, device.name
286
+ end
287
+ end
261
288
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-23 00:00:00.000000000 Z
11
+ date: 2020-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -215,6 +215,7 @@ files:
215
215
  - lib/browser/device/playstation4.rb
216
216
  - lib/browser/device/psp.rb
217
217
  - lib/browser/device/psvita.rb
218
+ - lib/browser/device/samsung.rb
218
219
  - lib/browser/device/surface.rb
219
220
  - lib/browser/device/switch.rb
220
221
  - lib/browser/device/tv.rb
@@ -283,6 +284,7 @@ files:
283
284
  - lib/browser/version.rb
284
285
  - lib/browser/weibo.rb
285
286
  - lib/browser/yandex.rb
287
+ - samsung.yml
286
288
  - search_engines.yml
287
289
  - test/browser_test.rb
288
290
  - test/middleware_test.rb
@@ -356,7 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
356
358
  - !ruby/object:Gem::Version
357
359
  version: '0'
358
360
  requirements: []
359
- rubygems_version: 3.1.2
361
+ rubygems_version: 3.1.4
360
362
  signing_key:
361
363
  specification_version: 4
362
364
  summary: Do some browser detection with Ruby.