sant0sk1-rack-noie6 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +8 -4
- data/Rakefile +1 -1
- data/VERSION.yml +2 -2
- data/lib/noie6.rb +11 -1
- data/test/noie6_test.rb +19 -0
- metadata +3 -2
data/README.markdown
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# rack-noie6
|
2
2
|
|
3
|
-
rack-noie6 does _everyone_ a favor: it shows the way out of your website to poor souls out there using Internet Explorer 6.
|
3
|
+
rack-noie6 does _everyone_ a favor: it shows the way out of your website to poor souls out there using Internet Explorer 6 (or a user configurable minimum).
|
4
4
|
|
5
|
-
Originally developed by [juliocesar](http://github.com/juliocesar).
|
5
|
+
Originally developed by [juliocesar](http://github.com/juliocesar), [sant0sk1](http://github.com/sant0sk1) forked and gemified for easier distribution and [I](http://github.com/wjessop) added the minimum version option.
|
6
6
|
|
7
7
|
# general usage
|
8
8
|
|
9
9
|
just
|
10
10
|
|
11
|
-
gem install
|
11
|
+
gem install wjessop-rack-noie6 --source http://gems.github.com
|
12
12
|
require 'noie6'
|
13
13
|
|
14
14
|
and
|
@@ -24,11 +24,15 @@ or let the default kick in
|
|
24
24
|
|
25
25
|
use Rack::NoIE6
|
26
26
|
|
27
|
+
You can even specify a minimum version of IE like so
|
28
|
+
|
29
|
+
use Rack::NoIE6, :redirect => 'http://slashdot.org', :minimum => 6.0
|
30
|
+
|
27
31
|
# Rails usage
|
28
32
|
|
29
33
|
inside environment.rb's Rails::Initializer.run
|
30
34
|
|
31
|
-
config.gem '
|
35
|
+
config.gem 'wjessop-rack-noie6', :lib => 'noie6'
|
32
36
|
config.middleware.use "Rack::NoIE6"
|
33
37
|
|
34
38
|
Piece o' cake!
|
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ begin
|
|
14
14
|
gemspec.summary = "A Rack middleware to redirect IE6 users out of your website"
|
15
15
|
gemspec.email = "jerod.santo@gmail.com"
|
16
16
|
gemspec.homepage = "http://github.com/sant0sk1/rack-noie6"
|
17
|
-
gemspec.authors = ["Jerod Santo", "Julio Cesar Ody"]
|
17
|
+
gemspec.authors = ["Jerod Santo", "Julio Cesar Ody", "Will Jessop"]
|
18
18
|
end
|
19
19
|
rescue LoadError
|
20
20
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION.yml
CHANGED
data/lib/noie6.rb
CHANGED
@@ -4,6 +4,7 @@ module Rack
|
|
4
4
|
@app = app
|
5
5
|
@options = options
|
6
6
|
@options[:redirect] ||= 'http://www.microsoft.com/windows/internet-explorer/default.aspx'
|
7
|
+
@options[:minimum] ||= 7.0
|
7
8
|
end
|
8
9
|
|
9
10
|
def call(env)
|
@@ -13,9 +14,18 @@ module Rack
|
|
13
14
|
private
|
14
15
|
def ie6_found_in?(env)
|
15
16
|
if env['HTTP_USER_AGENT']
|
16
|
-
env['HTTP_USER_AGENT'][
|
17
|
+
is_ie?(env['HTTP_USER_AGENT']) and ie_version(env['HTTP_USER_AGENT']) < @options[:minimum] and @options[:redirect] != env['PATH_INFO']
|
17
18
|
end
|
18
19
|
end
|
20
|
+
|
21
|
+
def is_ie?(ua_string)
|
22
|
+
# We need at least one digit to be able to get the version, hence the \d
|
23
|
+
ua_string.match(/MSIE \d/) ? true : false
|
24
|
+
end
|
25
|
+
|
26
|
+
def ie_version(ua_string)
|
27
|
+
ua_string.match(/MSIE (\S+)/)[1].to_f
|
28
|
+
end
|
19
29
|
|
20
30
|
def kick_it
|
21
31
|
[301, {'Location' => @options[:redirect]}, 'Fail browser is fail']
|
data/test/noie6_test.rb
CHANGED
@@ -20,6 +20,13 @@ class NoieTest < Test::Unit::TestCase
|
|
20
20
|
assert_equal response.location, 'http://slashdot.org'
|
21
21
|
end
|
22
22
|
|
23
|
+
def test_redirects_to_where_it_should_if_user_specified_minimum_not_met
|
24
|
+
request = Rack::MockRequest.new(Rack::NoIE6.new(TestApp.new, {:redirect => 'http://slashdot.org', :minimum => 6.0}))
|
25
|
+
response = request.get('/', {'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE 5.5b1; Mac_PowerPC)' })
|
26
|
+
assert_equal 301, response.status
|
27
|
+
assert_equal response.location, 'http://slashdot.org'
|
28
|
+
end
|
29
|
+
|
23
30
|
def test_redirects_to_local_urls
|
24
31
|
request = Rack::MockRequest.new(Rack::NoIE6.new(TestApp.new, {:redirect => '/foo'}))
|
25
32
|
response = request.get('/foo', {'HTTP_USER_AGENT' => 'MSIE 6.0' })
|
@@ -32,6 +39,18 @@ class NoieTest < Test::Unit::TestCase
|
|
32
39
|
assert_equal "Hi Internets!", response.body
|
33
40
|
end
|
34
41
|
|
42
|
+
def test_allows_if_UA_version_greater_than_minimum
|
43
|
+
request = Rack::MockRequest.new(Rack::NoIE6.new(TestApp.new, {:redirect => 'http://slashdot.org'}))
|
44
|
+
response = request.get('/', {'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows XP)'})
|
45
|
+
assert_equal "Hi Internets!", response.body
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_allows_if_no_UA_version_no_available
|
49
|
+
request = Rack::MockRequest.new(Rack::NoIE6.new(TestApp.new, {:redirect => 'http://slashdot.org'}))
|
50
|
+
response = request.get('/', {'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE l4me; Windows XP)'})
|
51
|
+
assert_equal "Hi Internets!", response.body
|
52
|
+
end
|
53
|
+
|
35
54
|
def test_allows_if_no_user_agent_specified
|
36
55
|
request = Rack::MockRequest.new(Rack::NoIE6.new(TestApp.new, {:redirect => 'http://slashdot.org'}))
|
37
56
|
response = request.get('/')
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sant0sk1-rack-noie6
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jerod Santo
|
8
8
|
- Julio Cesar Ody
|
9
|
+
- Will Jessop
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
13
|
|
13
|
-
date: 2009-05-
|
14
|
+
date: 2009-05-30 00:00:00 -07:00
|
14
15
|
default_executable:
|
15
16
|
dependencies: []
|
16
17
|
|