browser 0.9.1 → 1.0.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
  SHA1:
3
- metadata.gz: eddee2b6db8afdf0d9c36a8a74f9517b76c215c7
4
- data.tar.gz: 74c6356881cef0f1caeb310286e10a5741cab185
3
+ metadata.gz: 56723cefb92ad8c20d18cb2a017daf3c4de241f7
4
+ data.tar.gz: 379fcae2f68d422e8684db80036c1942c8d6250c
5
5
  SHA512:
6
- metadata.gz: e536d711e96ccb39895a5bdde0d6c7425c740fe2ab81201a8db257f56b1e26d586388d339ff12b49a09716e0876188a938becf50c20d96225a07008054eaa239
7
- data.tar.gz: 18c18599e9891ada9c6dadeaf42181390037f53830c8fe541efeeb307646716ab80f37bc071cb112ca205416a48531cf39d14b0a1259bf1fdbc9709498ee8c27
6
+ metadata.gz: 289a8912aed75c7c481a4838eadca09a8110a5b6e6a4133283bd32ca3bba52a474514a5754da1d992d1857455bc2982f2de402c6daf039f9e95d51ebf7dc9c9e
7
+ data.tar.gz: cbd3e177f309122a566f8fd85d6f39f5ad117305bab74b3e03f9a410cbdbfc34bb18663fb392727157032a505c1eae6cf0cf7af349bdd525b8563fddc0727d01
data/.travis.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
2
4
  rvm:
3
5
  - '2.2'
4
6
  - '2.1'
@@ -7,3 +9,5 @@ gemfile:
7
9
  - Gemfile
8
10
  - gemfiles/rails3.gemfile
9
11
  script: "bundle exec rake spec"
12
+ notifications:
13
+ email: false
data/README.md CHANGED
@@ -87,6 +87,34 @@ This adds a helper method called `browser`, that inspects your current user agen
87
87
  <% end %>
88
88
  ```
89
89
 
90
+ ### Internet Explorer
91
+
92
+ 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`.
93
+
94
+ So, let's say an user activates compatibility view in a IE11 browser. This is what you'll get:
95
+
96
+ ```ruby
97
+ browser.version
98
+ #=> 11
99
+
100
+ browser.full_version
101
+ #=> 11.0
102
+
103
+ browser.msie_version
104
+ #=> 7
105
+
106
+ browser.msie_full_version
107
+ #=> 7.0
108
+
109
+ browser.compatibility_view?
110
+ #=> true
111
+
112
+ browser.modern?
113
+ #=> false
114
+ ```
115
+
116
+ This behavior changed in `v1.0.0`; previously there wasn't a way of getting the real browser version.
117
+
90
118
  ### Bots
91
119
 
92
120
  Browser used to detect empty user agents as bots, but this behaviour has changed. If you want to bring this detection back, you can activate it through the following call:
data/browser.gemspec CHANGED
@@ -18,6 +18,18 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
+ s.post_install_message = [
22
+ "",
23
+ "#################### WARNING ##############################" ,
24
+ "# #" ,
25
+ "# Internet Explorer detection has changed on v1.0.0+. #" ,
26
+ "# If this is important for you, please read #" ,
27
+ "# https://github.com/fnando/browser#internet-explorer #" ,
28
+ "# #" ,
29
+ "###########################################################" ,
30
+ "\n"
31
+ ].join("\n")
32
+
21
33
  s.add_development_dependency "bundler", ">= 0"
22
34
  s.add_development_dependency "rake"
23
35
  s.add_development_dependency "rails"
data/lib/browser.rb CHANGED
@@ -90,8 +90,8 @@ class Browser
90
90
  self.modern_rules.tap do |rules|
91
91
  rules << -> b { b.webkit? }
92
92
  rules << -> b { b.firefox? && b.version.to_i >= 17 }
93
- rules << -> b { b.ie? && b.version.to_i >= 9 }
94
- rules << -> b { b.edge? }
93
+ rules << -> b { b.ie? && b.version.to_i >= 9 && !b.compatibility_view? }
94
+ rules << -> b { b.edge? && !b.compatibility_view? }
95
95
  rules << -> b { b.opera? && b.version.to_i >= 12 }
96
96
  rules << -> b { b.firefox? && b.tablet? && b.android? && b.version.to_i >= 14 }
97
97
  end
@@ -124,13 +124,21 @@ class Browser
124
124
 
125
125
  # Return major version.
126
126
  def version
127
- full_version.to_s.split(".").first
127
+ if ie?
128
+ ie_version
129
+ else
130
+ full_version.to_s.split(".").first
131
+ end
128
132
  end
129
133
 
130
134
  # Return the full version.
131
135
  def full_version
132
- _, *v = *ua.match(VERSIONS.fetch(id, VERSIONS[:default]))
133
- v.compact.first || "0.0"
136
+ if ie?
137
+ ie_full_version
138
+ else
139
+ _, *v = *ua.match(VERSIONS.fetch(id, VERSIONS[:default]))
140
+ v.compact.first || "0.0"
141
+ end
134
142
  end
135
143
 
136
144
  # Return true if browser is modern (Webkit, Firefox 17+, IE9+, Opera 12+).
@@ -177,11 +185,6 @@ class Browser
177
185
  ua =~ /Chrome|CriOS/ && !opera? && !edge?
178
186
  end
179
187
 
180
- # Detect if browser is Microsoft Edge.
181
- def edge?
182
- !!(ua =~ /Windows.*?\bEdge\/\d+/)
183
- end
184
-
185
188
  # Detect if browser is Opera.
186
189
  def opera?
187
190
  !!(ua =~ /(Opera|OPR)/)
@@ -2,6 +2,38 @@ class Browser
2
2
  module IE
3
3
  TRIDENT_VERSION_REGEX = %r[Trident/([0-9.]+)]
4
4
  MODERN_IE = %r[Trident/.*?; rv:(.*?)]
5
+ MSIE = %r{MSIE ([\d.]+)|Trident/.*?; rv:([\d.]+)}
6
+ EDGE = %r{(Edge/[\d.]+|Trident/8)}
7
+
8
+ # https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx#TriToken
9
+ TRIDENT_MAPPING = {
10
+ "4.0" => "8",
11
+ "5.0" => "9",
12
+ "6.0" => "10",
13
+ "7.0" => "11",
14
+ "8.0" => "12"
15
+ }
16
+
17
+ def ie_version
18
+ TRIDENT_MAPPING[trident_version] || msie_version
19
+ end
20
+
21
+ def ie_full_version
22
+ "#{ie_version}.0"
23
+ end
24
+
25
+ def msie_full_version
26
+ ua.match(MSIE) && ($1 || $2)
27
+ end
28
+
29
+ def msie_version
30
+ msie_full_version.split(".").first
31
+ end
32
+
33
+ # Return the trident version.
34
+ def trident_version
35
+ ua.match(TRIDENT_VERSION_REGEX) && $1
36
+ end
5
37
 
6
38
  # Detect if browser is Internet Explorer.
7
39
  def ie?
@@ -38,10 +70,14 @@ class Browser
38
70
  ie? && version == "11"
39
71
  end
40
72
 
73
+ # Detect if browser is Microsoft Edge.
74
+ def edge?
75
+ !!(ua =~ EDGE)
76
+ end
77
+
41
78
  # Detect if IE is running in compatibility mode.
42
79
  def compatibility_view?
43
- match = ua.match(TRIDENT_VERSION_REGEX)
44
- ie? && match && version.to_i < (match[1].to_i + 4)
80
+ ie? && trident_version && msie_version.to_i < (trident_version.to_i + 4)
45
81
  end
46
82
 
47
83
  private
@@ -1,8 +1,8 @@
1
1
  class Browser
2
2
  module Version
3
- MAJOR = 0
4
- MINOR = 9
5
- PATCH = 1
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/test/browser_spec.rb CHANGED
@@ -181,12 +181,13 @@ describe Browser do
181
181
 
182
182
  assert_equal "Internet Explorer", @browser.name
183
183
  assert @browser.ie?
184
- assert @browser.ie7?
185
- refute @browser.ie8?
184
+ assert @browser.ie8?
186
185
  refute @browser.modern?
187
186
  assert @browser.compatibility_view?
188
- assert_equal "7.0", @browser.full_version
189
- assert_equal "7", @browser.version
187
+ assert_equal "8.0", @browser.full_version
188
+ assert_equal "8", @browser.version
189
+ assert_equal "7.0", @browser.msie_full_version
190
+ assert_equal "7", @browser.msie_version
190
191
  end
191
192
 
192
193
  it "detects ie9" do
@@ -206,12 +207,13 @@ describe Browser do
206
207
 
207
208
  assert_equal "Internet Explorer", @browser.name
208
209
  assert @browser.ie?
209
- assert @browser.ie7?
210
- refute @browser.ie9?
210
+ assert @browser.ie9?
211
211
  refute @browser.modern?
212
212
  assert @browser.compatibility_view?
213
- assert_equal "7.0", @browser.full_version
214
- assert_equal "7", @browser.version
213
+ assert_equal "9.0", @browser.full_version
214
+ assert_equal "9", @browser.version
215
+ assert_equal "7.0", @browser.msie_full_version
216
+ assert_equal "7", @browser.msie_version
215
217
  end
216
218
 
217
219
  it "detects ie10" do
@@ -231,12 +233,13 @@ describe Browser do
231
233
 
232
234
  assert_equal "Internet Explorer", @browser.name
233
235
  assert @browser.ie?
234
- assert @browser.ie7?
235
- refute @browser.ie10?
236
+ assert @browser.ie10?
236
237
  refute @browser.modern?
237
238
  assert @browser.compatibility_view?
238
- assert_equal "7.0", @browser.full_version
239
- assert_equal "7", @browser.version
239
+ assert_equal "10.0", @browser.full_version
240
+ assert_equal "10", @browser.version
241
+ assert_equal "7.0", @browser.msie_full_version
242
+ assert_equal "7", @browser.msie_version
240
243
  end
241
244
 
242
245
  it "detects ie11" do
@@ -251,6 +254,20 @@ describe Browser do
251
254
  assert_equal "11", @browser.version
252
255
  end
253
256
 
257
+ it "detects ie11 in compatibility view" do
258
+ @browser.ua = $ua["IE11_COMPAT"]
259
+
260
+ assert_equal "Internet Explorer", @browser.name
261
+ assert @browser.ie?
262
+ assert @browser.ie11?
263
+ refute @browser.modern?
264
+ assert @browser.compatibility_view?
265
+ assert_equal "11.0", @browser.full_version
266
+ assert_equal "11", @browser.version
267
+ assert_equal "7.0", @browser.msie_full_version
268
+ assert_equal "7", @browser.msie_version
269
+ end
270
+
254
271
  it "detects Lumia 800" do
255
272
  @browser.ua = $ua["LUMIA800"]
256
273
 
@@ -826,6 +843,24 @@ describe Browser do
826
843
  refute @browser.mobile?
827
844
  end
828
845
 
846
+ it "detects Microsoft Edge in compatibility view" do
847
+ @browser.ua = $ua["MS_EDGE_COMPAT"]
848
+
849
+ assert_equal :edge, @browser.id
850
+ assert_equal "Microsoft Edge", @browser.name
851
+ assert_equal "12.0", @browser.full_version
852
+ assert_equal "12", @browser.version
853
+ assert_equal "7.0", @browser.msie_full_version
854
+ assert_equal "7", @browser.msie_version
855
+ assert @browser.edge?
856
+ assert @browser.compatibility_view?
857
+ refute @browser.modern?
858
+ refute @browser.webkit?
859
+ refute @browser.chrome?
860
+ refute @browser.safari?
861
+ refute @browser.mobile?
862
+ end
863
+
829
864
  it "detects Microsoft Edge Mobile" do
830
865
  @browser.ua = $ua["MS_EDGE_MOBILE"]
831
866
 
data/test/ua.yml CHANGED
@@ -28,6 +28,7 @@ IE10_COMPAT: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/6.0; SL
28
28
  IE10_X64_WINX64: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)'
29
29
  IE11: 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko'
30
30
  IE11_TOUCH_SCREEN: 'Mozilla/5.0 (Windows NT 6.3; Win64; x64; Trident/7.0; Touch; rv:11.0) like Gecko'
31
+ IE11_COMPAT: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729)'
31
32
  IE6: 'Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)'
32
33
  IE7: 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)'
33
34
  IE8: 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)'
@@ -35,6 +36,7 @@ IE8_COMPAT: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; SLC
35
36
  IE9: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
36
37
  IE9_COMPAT: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)'
37
38
  MS_EDGE: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0'
39
+ MS_EDGE_COMPAT: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/8.0; .NET4.0C; .NET4.0E; Tablet PC 2.0; Microsoft Outlook 15.0.4433; ms-office; MSOffice 15)'
38
40
  MS_EDGE_MOBILE: 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; DEVICE INFO) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Mobile Safari/537.36 Edge/12.0'
39
41
  IOS4: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7'
40
42
  IOS5: 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3'
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: 0.9.1
4
+ version: 1.0.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: 2015-07-31 00:00:00.000000000 Z
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,7 +150,16 @@ homepage: http://github.com/fnando/browser
150
150
  licenses:
151
151
  - MIT
152
152
  metadata: {}
153
- post_install_message:
153
+ post_install_message: |2+
154
+
155
+ #################### WARNING ##############################
156
+ # #
157
+ # Internet Explorer detection has changed on v1.0.0+. #
158
+ # If this is important for you, please read #
159
+ # https://github.com/fnando/browser#internet-explorer #
160
+ # #
161
+ ###########################################################
162
+
154
163
  rdoc_options: []
155
164
  require_paths:
156
165
  - lib
@@ -166,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
175
  version: '0'
167
176
  requirements: []
168
177
  rubyforge_project:
169
- rubygems_version: 2.4.6
178
+ rubygems_version: 2.4.5.1
170
179
  signing_key:
171
180
  specification_version: 4
172
181
  summary: Do some browser detection with Ruby.