http_router 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
data/http_router.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency 'rbench'
29
29
  s.add_development_dependency 'phocus'
30
30
  s.add_development_dependency 'bundler', '~> 1.0.0'
31
- s.add_development_dependency 'thin', '~> 1.2.7'
31
+ s.add_development_dependency 'thin', '= 1.2.8'
32
32
 
33
33
  if s.respond_to? :specification_version then
34
34
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -8,7 +8,7 @@ class HttpRouter
8
8
  case @chars.first[0]
9
9
  when ?( then @chars.shift and double_paths
10
10
  when ?) then @chars.shift and half_paths
11
- when ?\\
11
+ when ?\\
12
12
  @chars[1] == ?( || @chars[1] == ?) ? @chars.shift : add_to_current_set(@chars.shift)
13
13
  add_to_current_set(@chars.shift)
14
14
  else
@@ -1,4 +1,5 @@
1
1
  require 'url_mount'
2
+ require 'uri'
2
3
 
3
4
  class HttpRouter
4
5
  class Route
@@ -209,7 +210,7 @@ class HttpRouter
209
210
  matches_with[name.to_sym] = @opts[name.to_sym]
210
211
  @opts[name.to_sym] ? node.add_spanning_match(@opts.delete(name.to_sym)) : node.add_glob
211
212
  else
212
- node.add_lookup(parts[0])
213
+ node.add_lookup(URI.encode(parts[0]))
213
214
  end
214
215
  else
215
216
  capturing_indicies = []
@@ -238,7 +239,7 @@ class HttpRouter
238
239
  "(#{(@opts[name] || '.*?')})"
239
240
  else
240
241
  priority += part.size
241
- Regexp.quote(part)
242
+ Regexp.quote(URI.encode(part))
242
243
  end
243
244
  end
244
245
  node = spans ? node.add_spanning_match(Regexp.new("#{regex}$"), capturing_indicies, priority, splitting_indicies) :
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  class HttpRouter #:nodoc
3
- VERSION = '0.6.8'
3
+ VERSION = '0.6.9'
4
4
  end
data/lib/http_router.rb CHANGED
@@ -33,7 +33,7 @@ class HttpRouter
33
33
  def initialize(*args, &blk)
34
34
  default_app, options = args.first.is_a?(Hash) ? [nil, args.first] : [args.first, args[1]]
35
35
  @options = options
36
- @default_app = default_app || options && options[:default_app] || proc{|env| ::Rack::Response.new("Not Found", 404).finish }
36
+ @default_app = default_app || options && options[:default_app] || proc{|env| ::Rack::Response.new("Not Found", 404, {'X-Cascade' => 'pass'}).finish }
37
37
  @ignore_trailing_slash = options && options.key?(:ignore_trailing_slash) ? options[:ignore_trailing_slash] : true
38
38
  @redirect_trailing_slash = options && options.key?(:redirect_trailing_slash) ? options[:redirect_trailing_slash] : false
39
39
  @known_methods = Set.new(options && options[:known_methods] || [])
@@ -119,7 +119,7 @@ class HttpRouter
119
119
  else
120
120
  request = Request.new(rack_request.path_info, rack_request, perform_call)
121
121
  response = catch(:success) { @root[request] }
122
- if !response
122
+ if response.nil?
123
123
  supported_methods = (@known_methods - [env['REQUEST_METHOD']]).select do |m|
124
124
  test_env = ::Rack::Request.new(rack_request.env.clone)
125
125
  test_env.env['REQUEST_METHOD'] = m
@@ -127,11 +127,13 @@ class HttpRouter
127
127
  test_request = Request.new(test_env.path_info, test_env, 405)
128
128
  catch(:success) { @root[test_request] }
129
129
  end
130
- supported_methods.empty? ? @default_app.call(env) : [405, {'Allow' => supported_methods.sort.join(", ")}, []]
130
+ supported_methods.empty? ? (perform_call ? @default_app.call(env) : nil) : [405, {'Allow' => supported_methods.sort.join(", ")}, []]
131
131
  elsif response
132
132
  response
133
- else
133
+ elsif perform_call
134
134
  @default_app.call(env)
135
+ else
136
+ nil
135
137
  end
136
138
  end
137
139
  end
@@ -96,10 +96,10 @@ class TestGenerate < MiniTest::Unit::TestCase
96
96
  end
97
97
 
98
98
  def test_hash
99
- assert_generate '/var?foo[az]=baz&foo[ar]=bar', '/var', :foo => {:az => 'baz', :ar => 'bar'}
99
+ assert_generate '/var?foo[az]=baz', '/var', :foo => {:az => 'baz'}
100
100
  end
101
101
 
102
102
  def test_hash_with_array
103
- assert_generate '/var?foo[az]=baz&foo[ar][]=bar&foo[ar][]=barz', '/var', :foo => {:az => 'baz', :ar => ['bar', 'barz']}
103
+ assert_generate '/var?foo[ar][]=bar', '/var', :foo => {:ar => ['bar']}
104
104
  end
105
105
  end
data/test/test_misc.rb CHANGED
@@ -1,15 +1,13 @@
1
1
  class TestMisc < MiniTest::Unit::TestCase
2
2
  def test_cloning
3
- r1 = HttpRouter.new {
4
- add('/test').name(:test_route).to :test
5
- }
3
+ r1 = HttpRouter.new { add('/test').name(:test_route).to(:test) }
6
4
  r2 = r1.clone
7
5
 
8
6
  r2.add('/test2').name(:test).to(:test2)
9
7
  assert_equal 2, r2.routes.size
10
8
 
11
- assert_equal 404, r1.recognize(Rack::Request.new(Rack::MockRequest.env_for('/test2'))).first
12
- assert r2.recognize(Rack::Request.new(Rack::MockRequest.env_for('/test2')))
9
+ assert_equal nil, r1.recognize(Rack::Request.new(Rack::MockRequest.env_for('/test2')))
10
+ assert r2.recognize(Rack::MockRequest.env_for('/test2'))
13
11
  assert_equal r1.routes.first, r1.named_routes[:test_route]
14
12
  assert_equal r2.routes.first, r2.named_routes[:test_route]
15
13
 
@@ -35,6 +35,10 @@ class TestRecognition < MiniTest::Unit::TestCase
35
35
  assert_route router.add('/test\*variable'), '/test*variable'
36
36
  end
37
37
 
38
+ def test_unicode
39
+ assert_route router.add('/føø'), '/f%C3%B8%C3%B8'
40
+ end
41
+
38
42
  def test_partial
39
43
  router.add("/test*").to { |env| Rack::Response.new(env['PATH_INFO']).finish }
40
44
  assert_body '/optional', router.call(Rack::MockRequest.env_for('/test/optional'))
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_router
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 8
10
- version: 0.6.8
9
+ - 9
10
+ version: 0.6.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-01 00:00:00 -07:00
18
+ date: 2011-04-07 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -144,14 +144,14 @@ dependencies:
144
144
  requirement: &id009 !ruby/object:Gem::Requirement
145
145
  none: false
146
146
  requirements:
147
- - - ~>
147
+ - - "="
148
148
  - !ruby/object:Gem::Version
149
- hash: 17
149
+ hash: 15
150
150
  segments:
151
151
  - 1
152
152
  - 2
153
- - 7
154
- version: 1.2.7
153
+ - 8
154
+ version: 1.2.8
155
155
  type: :development
156
156
  version_requirements: *id009
157
157
  description: This library allows you to recognize and build URLs in a Rack application.