browser 0.4.0 → 0.4.1

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: d33f512a1af14cd694c0268b45aa9b197f5011fd
4
- data.tar.gz: 73de6e2670165e5b7de2b1966ad67a7863afe55a
3
+ metadata.gz: 4b3b6a159e6f696022dbcf224f2366040a014066
4
+ data.tar.gz: 12cfb603efd44bfa40a6211dc81cdbfc8cc3175a
5
5
  SHA512:
6
- metadata.gz: 69b2e09e88e616b7942e63285d704459002d39264f604ae46397ac8b198c5fcd2fe18663730076709b406b55986b13d7e041913bc584c0e5f132db59df3abf6a
7
- data.tar.gz: 45c8ae00d05cc760f415e56a68ab7689a1f3d62f292f72ad5316f931769c56bca9b6a8ec10b09dec68cfe17c8b9bbcb31a364e11fd216ba3a01817ed6df9085a
6
+ metadata.gz: 73d07937171c917f60c801a15f6d7ad4fe637d041c49b7fee0eb0327d8cbeaeeda0e1322ee08e208021e689ff7a357e4af6aa1e9d532f7e4705fda8289511de2
7
+ data.tar.gz: bcee3558d4278b99921b93d6eb8763d640c475da9e5351b6c3f8f692ba6f7984427d2020c5eb0ad146b34d70286ef020731c7fd73732650672da3b3136e178fe
@@ -5,6 +5,9 @@ class Browser
5
5
  # Detect the most common assets.
6
6
  ASSETS_REGEX = %r[\.(css|png|jpe?g|gif|js|svg|ico|flv|mov|m4v|ogg|swf)\z]i
7
7
 
8
+ # Detect the ACCEPT header. IE8 send */*.
9
+ ACCEPT_REGEX = %r[(text/html|\*/\*)]
10
+
8
11
  def initialize(app, &block)
9
12
  raise ArgumentError, "Browser::Middleware requires a block" unless block
10
13
 
@@ -18,7 +21,7 @@ class Browser
18
21
  # Only apply verification on HTML requests.
19
22
  # This ensures that images, CSS and JavaScript
20
23
  # will be rendered.
21
- return run_app(env) unless html?(request)
24
+ return run_app(env) unless process?(request)
22
25
 
23
26
  path = catch(:redirected) do
24
27
  Context.new(request).instance_eval(&@block)
@@ -48,9 +51,16 @@ class Browser
48
51
  @app.call(env)
49
52
  end
50
53
 
54
+ def process?(request)
55
+ html?(request) && !assets?(request)
56
+ end
57
+
51
58
  def html?(request)
52
- return if request.path.match(ASSETS_REGEX)
53
- request.env["HTTP_ACCEPT"].to_s.include?("text/html")
59
+ request.env["HTTP_ACCEPT"].to_s.match(ACCEPT_REGEX)
60
+ end
61
+
62
+ def assets?(request)
63
+ request.path.match(ASSETS_REGEX)
54
64
  end
55
65
  end
56
66
  end
@@ -2,7 +2,7 @@ class Browser
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- PATCH = 0
5
+ PATCH = 1
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -35,6 +35,13 @@ class MiddlewareTest < Test::Unit::TestCase
35
35
  assert_equal 404, last_response.status
36
36
  end
37
37
 
38
+ def test_redirect_ie8_with_wildcard_http_accept
39
+ get "/", {}, {"HTTP_USER_AGENT" => "MSIE 8", "HTTP_ACCEPT" => "*/*"}
40
+ follow_redirect!
41
+
42
+ assert_equal 404, last_response.status
43
+ end
44
+
38
45
  def test_ignores_non_html_requests
39
46
  get "/", {}, {"HTTP_USER_AGENT" => "MSIE 6", "HTTP_ACCEPT" => "image/png"}
40
47
 
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-07 00:00:00.000000000 Z
11
+ date: 2014-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  version: '0'
160
160
  requirements: []
161
161
  rubyforge_project:
162
- rubygems_version: 2.2.0
162
+ rubygems_version: 2.2.2
163
163
  signing_key:
164
164
  specification_version: 4
165
165
  summary: Do some browser detection with Ruby.