browser 3.0.2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +1 -1
  3. data/.prettierignore +1 -0
  4. data/.rubocop.yml +9 -0
  5. data/.travis.yml +3 -3
  6. data/CHANGELOG.md +81 -18
  7. data/FUNDING.yml +3 -0
  8. data/README.md +113 -88
  9. data/bots.yml +300 -294
  10. data/browser.gemspec +3 -1
  11. data/lib/browser/base.rb +63 -7
  12. data/lib/browser/browser.rb +27 -26
  13. data/lib/browser/chrome.rb +12 -2
  14. data/lib/browser/device.rb +2 -2
  15. data/lib/browser/device/unknown.rb +1 -1
  16. data/lib/browser/duck_duck_go.rb +22 -0
  17. data/lib/browser/edge.rb +2 -2
  18. data/lib/browser/google_search_app.rb +21 -0
  19. data/lib/browser/huawei_browser.rb +21 -0
  20. data/lib/browser/maxthon.rb +21 -0
  21. data/lib/browser/meta.rb +0 -1
  22. data/lib/browser/meta/base.rb +0 -1
  23. data/lib/browser/miui_browser.rb +21 -0
  24. data/lib/browser/platform.rb +5 -5
  25. data/lib/browser/platform/base.rb +3 -2
  26. data/lib/browser/platform/ios.rb +1 -1
  27. data/lib/browser/platform/mac.rb +4 -2
  28. data/lib/browser/platform/{other.rb → unknown.rb} +3 -3
  29. data/lib/browser/platform/windows.rb +1 -1
  30. data/lib/browser/safari.rb +16 -1
  31. data/lib/browser/samsung_browser.rb +21 -0
  32. data/lib/browser/sougou_browser.rb +24 -0
  33. data/lib/browser/{generic.rb → unknown.rb} +3 -3
  34. data/lib/browser/version.rb +1 -1
  35. data/test/browser_test.rb +23 -6
  36. data/test/test_helper.rb +8 -0
  37. data/test/ua.yml +17 -1
  38. data/test/ua_bots.yml +8 -2
  39. data/test/unit/adobe_air_test.rb +1 -1
  40. data/test/unit/alipay_test.rb +6 -0
  41. data/test/unit/console_test.rb +2 -2
  42. data/test/unit/device_test.rb +2 -2
  43. data/test/unit/duck_duck_go_test.rb +37 -0
  44. data/test/unit/edge_test.rb +34 -2
  45. data/test/unit/google_search_app_test.rb +54 -0
  46. data/test/unit/huawei_browser_test.rb +25 -0
  47. data/test/unit/maxthon_test.rb +25 -0
  48. data/test/unit/meta_test.rb +9 -0
  49. data/test/unit/micro_messenger_test.rb +21 -6
  50. data/test/unit/miui_browser_test.rb +25 -0
  51. data/test/unit/opera_test.rb +1 -0
  52. data/test/unit/platform_test.rb +12 -7
  53. data/test/unit/qq_test.rb +12 -0
  54. data/test/unit/safari_test.rb +12 -7
  55. data/test/unit/samsung_browser_test.rb +23 -0
  56. data/test/unit/sougou_browser_test.rb +41 -0
  57. metadata +33 -10
  58. data/lib/browser/meta/modern.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8cf4326bc2b2d9ef069fdedd8c6be7a58ca40b7d3cb33ca0264db7df79504bc
4
- data.tar.gz: bd6e16613c80c97b9aa0895baf7991088aa19946f3daeef27db2f5fadcfd171d
3
+ metadata.gz: 78fd9a10d5ca6461be5395616edcc1456967a595363f027548bf8a9fa0bfdf10
4
+ data.tar.gz: 599be9a3080333b44234ecf4c7ec21572e81e5dc3d04fccfa66a631bc6897494
5
5
  SHA512:
6
- metadata.gz: 809f13b58435f1e26b7dcf188aa9b4bbe3bad566b8139c82399060794cbfb2a99747893de20c07687a85db5ec38463561d45f6f61b2020b36155c4be794a7182
7
- data.tar.gz: 9fb22873f199a46dbfd709b75f7bf5cea2a8ef515ba4beaffdf10f2bbf9e395b18e77888deaaeace0ce7e5e201429bc7ebbdf138bf0690e6fec93a296aa2d61a
6
+ metadata.gz: ca6e173a47d2d1489816eb4794c57abc4fc3ff6f1ae63826570c71213e1177813895595240c995704ff50d22666ddae78900ac8eeea77cff93f3f63397bf4d7a
7
+ data.tar.gz: a09fe431f93c0dc9dd24ae2b1679538c4f61586b8334458adb41e6475c50da5850a747e1630b3904be57ccc360bc12333632cf1986978417e690aca4f8747356
@@ -27,4 +27,4 @@
27
27
 
28
28
  ## Report
29
29
 
30
- [Visit <http://user-agent.herokuapp.com> and paste the URL here]
30
+ [Visit <https://user-agent.herokuapp.com> and paste the URL here]
@@ -0,0 +1 @@
1
+ *.yml
@@ -27,3 +27,12 @@ Style/Alias:
27
27
 
28
28
  Lint/RedundantCopDisableDirective:
29
29
  Enabled: false
30
+
31
+ Metrics/AbcSize:
32
+ Enabled: false
33
+
34
+ Metrics/CyclomaticComplexity:
35
+ Enabled: false
36
+
37
+ Metrics/PerceivedComplexity:
38
+ Enabled: false
@@ -1,10 +1,10 @@
1
1
  ---
2
2
  language: ruby
3
- sudo: false
4
3
  cache: bundler
5
4
  rvm:
6
- - 2.6.0
7
- - 2.5.0
5
+ - 2.7
6
+ - 2.6
7
+ - 2.5
8
8
  gemfile:
9
9
  - Gemfile
10
10
  - gemfiles/rails5.gemfile
@@ -1,8 +1,55 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
4
-
5
- - Nothing yet.
3
+ ## 5.0.0
4
+
5
+ - Rename `Browser::Platform#other?` to `Browser::Platform#unknown?`.
6
+ - Unknown platforms now return `:unknown_platform` as the id.
7
+ - Unknown devices now return `:unknown_device` as the id.
8
+ - Unknown browsers now return `:unknown_browser` as the id.
9
+ - All the changes above affect how `browser.meta` is composed.
10
+ - Add method `Browser::Base#unknown?`.
11
+ - Fix issue with `Browser::Base#safari?` matching full version.
12
+ - Add Maxthon detection.
13
+ - Add Google Search App detection.
14
+ - Add Huawei Browser detection.
15
+ - Fix Duck Duck Go browser that was being recognized as a bot.
16
+ - Add Miui Browser detection.
17
+ - Add `Browser::Base#qq?`.
18
+ - Fix QQ detection.
19
+ - Fix Alipay detection.
20
+ - Add Sougou Browser detection.
21
+ - User agent has a size limit of 512 bytes. This can be customized through
22
+ `Browser.user_agent_size_limit`.
23
+ - Accept-Language has a size limit of 256 bytes. This can be customized through
24
+ `Browser.accept_language_size_limit`.
25
+
26
+ ## 4.2.0
27
+
28
+ - Fix Chrome Lighthouse detection.
29
+ - Add Skype to bot list.
30
+
31
+ ## 4.1.0
32
+
33
+ - Add Samsung browser.
34
+ - Add Google Image Proxy to the bot list.
35
+ - Add The Knowledge AI bot to the bot list.
36
+ - Add Go HttpClient to the bot list.
37
+ - Fix Microsoft Edge detection on Android and iOS.
38
+ - Fix MicroMessenger detection on Android
39
+
40
+ ## 4.0.0
41
+
42
+ - Add Chrome Lighthouse to bot list.
43
+ - Add SeobilityBot to the bot list.
44
+ - Detect Mac-based platforms differently, depending on the version; "Mac OS X"
45
+ will be returned for versions prior to 10.12, and "macOS" for newer versions.
46
+ - Remove `Browser.modern_rules` and `Browser::Base#modern?`.
47
+ - Add DuckDuckGo browser.
48
+
49
+ # 3.0.3
50
+
51
+ - Deprecate `Browser.modern_rules` and `Browser::Base#modern?`. Theses methods
52
+ will be removed on the next major released, or by June 1st 2020.
6
53
 
7
54
  ## 3.0.2
8
55
 
@@ -17,23 +64,32 @@
17
64
  - Add ArchiveTeam's ArchiveBot to the bot list.
18
65
  - Fix QQ Browser detection.
19
66
  - Update modern rules.
20
- - You can now define new bot matchers by adding a callable object to `Browser::Bot.matchers`.
67
+ - You can now define new bot matchers by adding a callable object to
68
+ `Browser::Bot.matchers`.
21
69
  - Fix `browser.yandex?` and `browser.sputnik?`.
22
- - [BREAKING CHANGE] Removed methods to enable the bot's empty user agent detection (`Browser::Bot.detect_empty_ua!` and `Browser::Bot.detect_empty_ua?`).
23
- - [BREAKING CHANGE] Bot detection is now more aggressive by default. It matches empty user agents, anything that matches `crawl|fetch|search|monitoring|spider|bot`, and anything listed under https://github.com/fnando/browser/blob/master/bots.yml.
70
+ - [BREAKING CHANGE] Removed methods to enable the bot's empty user agent
71
+ detection (`Browser::Bot.detect_empty_ua!` and
72
+ `Browser::Bot.detect_empty_ua?`).
73
+ - [BREAKING CHANGE] Bot detection is now more aggressive by default. It matches
74
+ empty user agents, anything that matches
75
+ `crawl|fetch|search|monitoring|spider|bot`, and anything listed under
76
+ https://github.com/fnando/browser/blob/master/bots.yml.
24
77
  - Add Jaunt to the bot list.
25
78
 
26
79
  ## 2.7.1
27
80
 
28
- - Handle Snapchat user agents that have a space or an empty string instead of a slash before the version.
81
+ - Handle Snapchat user agents that have a space or an empty string instead of a
82
+ slash before the version.
29
83
  - Fix iOS 10+ version detection.
30
- - Add fallback versions for instagram and snapchat to avoid NoMethodErrors on unexpected user agents.
84
+ - Add fallback versions for instagram and snapchat to avoid NoMethodErrors on
85
+ unexpected user agents.
31
86
 
32
87
  ## 2.7.0
33
88
 
34
89
  - Add more Slack bots.
35
90
  - Handle instagram user agents that have a slash instead of a space.
36
- - Add `Browser::Bot.why?(ua)` to help debugging why a user agent is considered bot.
91
+ - Add `Browser::Bot.why?(ua)` to help debugging why a user agent is considered
92
+ bot.
37
93
  - Promote Snapchat to a browser (it was detected as a bot previously).
38
94
  - Detect Edge based on Chrome correctly.
39
95
  - Improve Yandex detection.
@@ -49,7 +105,8 @@
49
105
 
50
106
  - Add GarlikCrawler, ImplisenseBot and WikiDo bots.
51
107
  - Add Mastodon URL expander bot.
52
- - Add eZ Publish Link Validator, GermCrawler, Pu_iN Crawler, ZoomBot, and ZoominfoBot bots.
108
+ - Add eZ Publish Link Validator, GermCrawler, Pu_iN Crawler, ZoomBot, and
109
+ ZoominfoBot bots.
53
110
  - Add Datanyze bot.
54
111
  - Add support for Instagram in-app browser.
55
112
  - Add Updown.io monitor bot.
@@ -71,13 +128,13 @@
71
128
  - Add Jooble bot.
72
129
  - Add Fyre bot.
73
130
  - Drop Rails 4 official support.
74
- - Fix accept-language sorting (If HTTP-header has value `en,fr`—without qualities—the first language should be `en` instead of `fr`).
131
+ - Fix accept-language sorting (If HTTP-header has value `en,fr`—without
132
+ qualities—the first language should be `en` instead of `fr`).
75
133
  - Ignore malformed strings when comparing versions.
76
134
  - Fix Facebook detection on newer apps.
77
135
  - Change precedence for bot detection when common libs are used.
78
136
  - Add Yandex's search browser to the exception list.
79
137
 
80
-
81
138
  ## v2.5.3
82
139
 
83
140
  - Add Google Site Verification to the bot list.
@@ -118,8 +175,10 @@
118
175
  - Add Google Drive API, Proximic Spider, NewRelic pinger and SocialRank bots.
119
176
  - Add Pinboard in-app browser to the bot exception list.
120
177
  - All browser detection methods can now compare versions.
121
- - All platform detection methods can now compare versions (except `#linux?` and `#firefox_os?`).
122
- - Add `browser/aliases`, so you can have methods on the base object (e.g. `browser.mobile?`). See README for instructions.
178
+ - All platform detection methods can now compare versions (except `#linux?` and
179
+ `#firefox_os?`).
180
+ - Add `browser/aliases`, so you can have methods on the base object (e.g.
181
+ `browser.mobile?`). See README for instructions.
123
182
  - Remove official support for Rails 3 and Ruby 2.1.
124
183
 
125
184
  ## v2.3.0
@@ -150,7 +209,8 @@
150
209
 
151
210
  ## v2.0.3
152
211
 
153
- - Fix issue with version detection when no actual version is provided (i.e. the user agent doesn't have any version information).
212
+ - Fix issue with version detection when no actual version is provided (i.e. the
213
+ user agent doesn't have any version information).
154
214
 
155
215
  ## v2.0.2
156
216
 
@@ -163,9 +223,12 @@
163
223
 
164
224
  ## v2.0.0
165
225
 
166
- - `Browser#platform` now returns instance of `Browser::Platform`, instead of a `String`. It contains information about the platform (software).
167
- - `Browser#device` was added. It returns information about the device (hardware).
168
- - `Browser#accept_language` now returns a list of `Browser::AcceptLanguage` objects.
226
+ - `Browser#platform` now returns instance of `Browser::Platform`, instead of a
227
+ `String`. It contains information about the platform (software).
228
+ - `Browser#device` was added. It returns information about the device
229
+ (hardware).
230
+ - `Browser#accept_language` now returns a list of `Browser::AcceptLanguage`
231
+ objects.
169
232
  - `Browser#bot` now returns a `Browser::Bot` instance.
170
233
  - Safari running as web app mode is not recognized as Safari anymore.
171
234
  - ruby-2.3+ will always activate frozen strings.
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [fnando]
data/README.md CHANGED
@@ -25,6 +25,7 @@ browser = Browser.new("Some User Agent", accept_language: "en-us")
25
25
  browser.bot?
26
26
  browser.chrome?
27
27
  browser.core_media?
28
+ browser.duck_duck_go?
28
29
  browser.edge? # Newest MS browser
29
30
  browser.electron? # Electron Framework
30
31
  browser.firefox?
@@ -33,8 +34,8 @@ browser.ie?
33
34
  browser.ie?(6) # detect specific IE version
34
35
  browser.ie?([">8", "<10"]) # detect specific IE (IE9).
35
36
  browser.known? # has the browser been successfully detected?
37
+ browser.unknown? # the browser wasn't detected.
36
38
  browser.meta # an array with several attributes
37
- browser.modern? # Webkit, Firefox 17+, IE 9+ and Opera 12+
38
39
  browser.name # readable browser name
39
40
  browser.nokia?
40
41
  browser.opera?
@@ -43,6 +44,7 @@ browser.phantom_js?
43
44
  browser.quicktime?
44
45
  browser.safari?
45
46
  browser.safari_webapp_mode?
47
+ browser.samsung_browser?
46
48
  browser.to_s # the meta info joined by space
47
49
  browser.uc_browser?
48
50
  browser.version # major version number
@@ -50,9 +52,11 @@ browser.webkit?
50
52
  browser.webkit_full_version
51
53
  browser.yandex?
52
54
  browser.wechat?
55
+ browser.qq?
53
56
  browser.weibo?
54
57
  browser.yandex?
55
58
  browser.sputnik?
59
+ browser.sougou_browser?
56
60
 
57
61
  # Get bot info
58
62
  browser.bot.name
@@ -65,6 +69,7 @@ Browser::Bot.why?(ua)
65
69
  browser.device
66
70
  browser.device.id
67
71
  browser.device.name
72
+ browser.device.unknown?
68
73
  browser.device.blackberry_playbook?
69
74
  browser.device.console?
70
75
  browser.device.ipad?
@@ -110,7 +115,7 @@ browser.platform.ios_app? # detect webview in an iOS app
110
115
  browser.platform.ios_webview? # alias for ios_app?
111
116
  browser.platform.linux?
112
117
  browser.platform.mac?
113
- browser.platform.other?
118
+ browser.platform.unknown?
114
119
  browser.platform.windows10?
115
120
  browser.platform.windows7?
116
121
  browser.platform.windows8?
@@ -129,7 +134,9 @@ browser.platform.windows_xp?
129
134
 
130
135
  ### Aliases
131
136
 
132
- To add aliases like `mobile?` and `tablet?` to the base object (e.g `browser.mobile?`), require the `browser/aliases` file and extend the Browser::Base object like the following:
137
+ To add aliases like `mobile?` and `tablet?` to the base object (e.g
138
+ `browser.mobile?`), require the `browser/aliases` file and extend the
139
+ Browser::Base object like the following:
133
140
 
134
141
  ```ruby
135
142
  require "browser/aliases"
@@ -141,27 +148,35 @@ browser.mobile? #=> false
141
148
 
142
149
  ### What's being detected?
143
150
 
144
- - For a list of platform detections, check [lib/browser/platform.rb](https://github.com/fnando/browser/blob/master/lib/browser/platform.rb)
145
- - For a list of device detections, check [lib/browser/device.rb](https://github.com/fnando/browser/blob/master/lib/browser/device.rb)
146
- - For a list of bot detections, check [bots.yml](https://github.com/fnando/browser/blob/master/bots.yml)
151
+ - For a list of platform detections, check
152
+ [lib/browser/platform.rb](https://github.com/fnando/browser/blob/master/lib/browser/platform.rb)
153
+ - For a list of device detections, check
154
+ [lib/browser/device.rb](https://github.com/fnando/browser/blob/master/lib/browser/device.rb)
155
+ - For a list of bot detections, check
156
+ [bots.yml](https://github.com/fnando/browser/blob/master/bots.yml)
147
157
 
148
- ### What defines a modern browser?
158
+ ### Detecting modern browsers
149
159
 
150
- The current rules that define a modern browser are pretty loose.
151
-
152
- * Chrome 65+
153
- * Safari 10+
154
- * Firefox 52+
155
- * IE11+
156
- * Microsoft Edge 39+
157
- * Opera 50+
158
-
159
- You can define your own rules. A rule must be a proc/lambda or any object that implements the method === and accepts the browser object. To redefine all rules, clear the existing rules before adding your own.
160
+ To detect whether a browser can be considered as modern or not, create a method
161
+ that abstracts your versioning constraints. The following example will consider
162
+ any of the following browsers as a modern:
160
163
 
161
164
  ```ruby
162
- # Only Google Chrome 79+ is considered modern.
163
- Browser.modern_rules.clear
164
- Browser.modern_rules << -> b { b.chrome? && b.version.to_i >= 79 }
165
+ # Expects an Browser instance,
166
+ # like in `Browser.new(user_agent, accept_language: language)`.
167
+ def modern_browser?(browser)
168
+ [
169
+ browser.chrome?(">= 65"),
170
+ browser.safari?(">= 10"),
171
+ browser.firefox?(">= 52"),
172
+ browser.ie?(">= 11") && !browser.compatibility_view?,
173
+ browser.edge?(">= 15"),
174
+ browser.opera?(">= 50"),
175
+ browser.facebook?
176
+ && browser.safari_webapp_mode?
177
+ && browser.webkit_full_version.to_i >= 602
178
+ ].any?
179
+ end
165
180
  ```
166
181
 
167
182
  ### Rails integration
@@ -172,7 +187,8 @@ Just add it to the Gemfile.
172
187
  gem "browser"
173
188
  ```
174
189
 
175
- This adds a helper method called `browser`, that inspects your current user agent.
190
+ This adds a helper method called `browser`, that inspects your current user
191
+ agent.
176
192
 
177
193
  ```erb
178
194
  <% if browser.ie?(6) %>
@@ -180,7 +196,8 @@ This adds a helper method called `browser`, that inspects your current user agen
180
196
  <% end %>
181
197
  ```
182
198
 
183
- If you want to use Browser on your Rails app but don't want to taint your controller, use the following line on your Gemfile:
199
+ If you want to use Browser on your Rails app but don't want to taint your
200
+ controller, use the following line on your Gemfile:
184
201
 
185
202
  ```ruby
186
203
  gem "browser", require: "browser/browser"
@@ -188,7 +205,8 @@ gem "browser", require: "browser/browser"
188
205
 
189
206
  ### Accept Language
190
207
 
191
- Parses the accept-language header from an HTTP request and produces an array of language objects sorted by quality.
208
+ Parses the accept-language header from an HTTP request and produces an array of
209
+ language objects sorted by quality.
192
210
 
193
211
  ```ruby
194
212
  browser = Browser.new("Some User Agent", accept_language: "en-us")
@@ -214,16 +232,22 @@ language.name
214
232
  #=> "English/United States"
215
233
  ```
216
234
 
217
- Result is always sorted in quality order from highest to lowest. As per the HTTP spec:
235
+ Result is always sorted in quality order from highest to lowest. As per the HTTP
236
+ spec:
218
237
 
219
238
  - omitting the quality value implies 1.0.
220
239
  - quality value equal to zero means that is not accepted by the client.
221
240
 
222
241
  ### Internet Explorer
223
242
 
224
- Internet Explorer has a compatibility view mode that allows newer versions (IE8+) to run as an older version. Browser will always return the navigator version, ignoring the compatibility view version, when defined. If you need to get the engine's version, you have to use `Browser#msie_version` and `Browser#msie_full_version`.
243
+ Internet Explorer has a compatibility view mode that allows newer versions
244
+ (IE8+) to run as an older version. Browser will always return the navigator
245
+ version, ignoring the compatibility view version, when defined. If you need to
246
+ get the engine's version, you have to use `Browser#msie_version` and
247
+ `Browser#msie_full_version`.
225
248
 
226
- So, let's say an user activates compatibility view in a IE11 browser. This is what you'll get:
249
+ So, let's say an user activates compatibility view in a IE11 browser. This is
250
+ what you'll get:
227
251
 
228
252
  ```ruby
229
253
  browser.version
@@ -240,16 +264,16 @@ browser.msie_full_version
240
264
 
241
265
  browser.compatibility_view?
242
266
  #=> true
243
-
244
- browser.modern?
245
- #=> false
246
267
  ```
247
268
 
248
- This behavior changed in `v1.0.0`; previously there wasn't a way of getting the real browser version.
269
+ This behavior changed in `v1.0.0`; previously there wasn't a way of getting the
270
+ real browser version.
249
271
 
250
272
  ### Safari
251
273
 
252
- iOS webviews and web apps aren't detected as Safari anymore, so be aware of that if that's your case. You can use a combination of platform and webkit detection to do whatever you want.
274
+ iOS webviews and web apps aren't detected as Safari anymore, so be aware of that
275
+ if that's your case. You can use a combination of platform and webkit detection
276
+ to do whatever you want.
253
277
 
254
278
  ```ruby
255
279
  # iPad's Safari running as web app mode.
@@ -267,19 +291,25 @@ browser.platform.ios?
267
291
 
268
292
  ### Bots
269
293
 
270
- The bot detection is quite aggressive. Anything that matches at least one of the following requirements will be considered a bot.
294
+ The bot detection is quite aggressive. Anything that matches at least one of the
295
+ following requirements will be considered a bot.
271
296
 
272
297
  - Empty user agent string
273
298
  - User agent that matches `/crawl|fetch|search|monitoring|spider|bot/`
274
- - Any known bot listed under [bots.yml](https://github.com/fnando/browser/blob/master/bots.yml)
299
+ - Any known bot listed under
300
+ [bots.yml](https://github.com/fnando/browser/blob/master/bots.yml)
275
301
 
276
- To add custom matchers, you can add a callable object to `Browser::Bot.matchers`. The following example matches everything that has a `externalhit` substring on it. The bot name will always be `General Bot`.
302
+ To add custom matchers, you can add a callable object to
303
+ `Browser::Bot.matchers`. The following example matches everything that has a
304
+ `externalhit` substring on it. The bot name will always be `General Bot`.
277
305
 
278
306
  ```ruby
279
307
  Browser::Bot.matchers << ->(ua, _browser) { ua =~ /externalhit/i }
280
308
  ```
281
309
 
282
- To clear all matchers, including the ones that are bundled, use `Browser::Bot.matchers.clear`. You can re-add built-in matchers by doing the following:
310
+ To clear all matchers, including the ones that are bundled, use
311
+ `Browser::Bot.matchers.clear`. You can re-add built-in matchers by doing the
312
+ following:
283
313
 
284
314
  ```ruby
285
315
  Browser::Bot.matchers += Browser::Bot.default_matchers
@@ -298,50 +328,41 @@ You can use the `Browser::Middleware` to redirect user agents.
298
328
 
299
329
  ```ruby
300
330
  use Browser::Middleware do
301
- redirect_to "/upgrade" unless browser.modern?
302
- end
303
- ```
304
-
305
- If you're using Rails, you can use the route helper methods. Just add something like the following to a initializer file (`config/initializers/browser.rb`).
306
-
307
- ```ruby
308
- Rails.configuration.middleware.use Browser::Middleware do
309
- redirect_to upgrade_path unless browser.modern?
331
+ redirect_to "/upgrade" if browser.ie?
310
332
  end
311
333
  ```
312
334
 
313
- Notice that you can have multiple conditionals.
335
+ If you're using Rails, you can use the route helper methods. Just add something
336
+ like the following to a initializer file (`config/initializers/browser.rb`).
314
337
 
315
338
  ```ruby
316
339
  Rails.configuration.middleware.use Browser::Middleware do
317
- next if browser.bot.search_engine?
318
- redirect_to upgrade_path(browser: "oldie") if browser.ie? && !browser.modern?
319
- redirect_to upgrade_path(browser: "oldfx") if browser.firefox? && !browser.modern?
340
+ redirect_to upgrade_path if browser.ie?
320
341
  end
321
342
  ```
322
343
 
323
- If you need access to the `Rack::Request` object (e.g. to exclude a path), you can do so with `request`.
344
+ If you need access to the `Rack::Request` object (e.g. to exclude a path), you
345
+ can do so with `request`.
324
346
 
325
347
  ```ruby
326
348
  Rails.configuration.middleware.use Browser::Middleware do
327
- redirect_to upgrade_path unless browser.modern? || request.env["PATH_INFO"] == "/exclude_me"
349
+ redirect_to upgrade_path if browser.ie? && request.env["PATH_INFO"] != "/exclude_me"
328
350
  end
329
351
  ```
330
352
 
331
- ### Migrating to v2
332
-
333
- #### Troubleshooting
353
+ ### Restrictions
334
354
 
335
- ##### `TypeError: no implicit conversion of Hash into String`
355
+ - User agent has a size limit of 512 bytes. This can be customized through
356
+ `Browser.user_agent_size_limit=(size)`.
357
+ - Accept-Language has a size limit of 256 bytes. This can be customized through
358
+ `Browser.accept_language_size_limit=(size)`.
336
359
 
337
- The class constructor now has a different signature. Change the instantiation from `Browser.new(options)` to `Browser.new(ua, options)`, where:
360
+ If size is not respected, then `Browser::Error` is raised.
338
361
 
339
- - `ua`: must be a string representing the user agent.
340
- - `options`: must be a hash (for now it only accepts the `accept_language` option).
341
-
342
- ##### `NoMethodError: undefined method 'user_agent'`
343
-
344
- `.ua` can now be used to retrieve the full User Agent string.
362
+ ```ruby
363
+ Browser.user_agent_size_limit = 1024
364
+ Browser.accept_language_size_limit = 150
365
+ ```
345
366
 
346
367
  ## Development
347
368
 
@@ -359,25 +380,28 @@ Once you've made your great commits (include tests, please):
359
380
  4. Create a pull request
360
381
  5. That's it!
361
382
 
362
- Please respect the indentation rules and code style.
363
- And use 2 spaces, not tabs. And don't touch the version thing.
383
+ Please respect the indentation rules and code style. And use 2 spaces, not tabs.
384
+ And don't touch the version thing.
364
385
 
365
386
  ## Configuring environment
366
387
 
367
- To configure your environment, you must have Ruby and bundler installed. Then run `bundle install` to install all dependencies.
388
+ To configure your environment, you must have Ruby and bundler installed. Then
389
+ run `bundle install` to install all dependencies.
368
390
 
369
391
  To run tests, execute `./bin/rake`.
370
392
 
371
393
  ### Adding new features
372
394
 
373
- Before using your time to code a new feature, open a ticket asking if it makes sense and if it's on this project's scope.
395
+ Before using your time to code a new feature, open a ticket asking if it makes
396
+ sense and if it's on this project's scope.
374
397
 
375
398
  Don't forget to add a new entry to `CHANGELOG.md`.
376
399
 
377
400
  #### Adding a new bot
378
401
 
379
402
  1. Add the user agent to `test/ua_bots.yml`.
380
- 2. Add the readable name to `bots.yml`. The key must be something that matches the user agent, in lowercased text.
403
+ 2. Add the readable name to `bots.yml`. The key must be something that matches
404
+ the user agent, in lowercased text.
381
405
  3. Run tests.
382
406
 
383
407
  Don't forget to add a new entry to `CHANGELOG.md`.
@@ -386,42 +410,43 @@ Don't forget to add a new entry to `CHANGELOG.md`.
386
410
 
387
411
  1. Add the user agent to `test/ua_search_engines.yml`.
388
412
  2. Add the same user agent to `test/ua_bots.yml`.
389
- 3. Add the readable name to `search_engines.yml`. The key must be something that matches the user agent, in lowercased text.
413
+ 3. Add the readable name to `search_engines.yml`. The key must be something that
414
+ matches the user agent, in lowercased text.
390
415
  4. Run tests.
391
416
 
392
417
  Don't forget to add a new entry to `CHANGELOG.md`.
393
418
 
394
419
  #### Wrong browser/platform/device detection
395
420
 
396
- If you know how to fix it, follow the "Writing code" above. Open an issue otherwise; make sure you fill in the issue template with all the required information.
421
+ If you know how to fix it, follow the "Writing code" above. Open an issue
422
+ otherwise; make sure you fill in the issue template with all the required
423
+ information.
397
424
 
398
425
  ## Maintainer
399
426
 
400
- * Nando Vieira - http://nandovieira.com
427
+ - Nando Vieira - http://nandovieira.com
401
428
 
402
429
  ## Contributors
403
430
 
404
- * https://github.com/fnando/browser/contributors
431
+ - https://github.com/fnando/browser/contributors
405
432
 
406
433
  ## License
407
434
 
408
435
  (The MIT License)
409
436
 
410
- Permission is hereby granted, free of charge, to any person obtaining
411
- a copy of this software and associated documentation files (the
412
- 'Software'), to deal in the Software without restriction, including
413
- without limitation the rights to use, copy, modify, merge, publish,
414
- distribute, sublicense, and/or sell copies of the Software, and to
415
- permit persons to whom the Software is furnished to do so, subject to
416
- the following conditions:
417
-
418
- The above copyright notice and this permission notice shall be
419
- included in all copies or substantial portions of the Software.
420
-
421
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
422
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
423
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
424
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
425
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
426
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
427
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
437
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
438
+ this software and associated documentation files (the 'Software'), to deal in
439
+ the Software without restriction, including without limitation the rights to
440
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
441
+ the Software, and to permit persons to whom the Software is furnished to do so,
442
+ subject to the following conditions:
443
+
444
+ The above copyright notice and this permission notice shall be included in all
445
+ copies or substantial portions of the Software.
446
+
447
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
448
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
449
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
450
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
451
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
452
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.