Skip to content
This repository
Browse code

added passed_with support, remove uri_escape

  • Loading branch information...
commit b283ade35f97435f4e2392e3429d5b829d4bbc3a 1 parent acf7b15
Josh Hull authored
2  http_router.gemspec
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24 24 s.add_runtime_dependency 'url_mount', '~> 0.2.1'
25 25 s.add_development_dependency 'minitest', '~> 2.0.0'
26 26 s.add_development_dependency 'code_stats'
27   - s.add_development_dependency 'rake'
  27 + s.add_development_dependency 'rake', '~> 0.8.7'
28 28 s.add_development_dependency 'rbench'
29 29 s.add_development_dependency 'phocus'
30 30 s.add_development_dependency 'bundler', '~> 1.0.0'
3  lib/http_router/node.rb
@@ -54,8 +54,7 @@ def add_destination(blk, partial)
54 54 end
55 55
56 56 def add_lookup(part)
57   - add(Lookup.new(@router))
58   - @matchers.last.add(part)
  57 + add(Lookup.new(@router)).add(part)
59 58 end
60 59
61 60 def usable?(other)
2  lib/http_router/node/destination.rb
@@ -8,7 +8,7 @@ def initialize(router, blk, allow_partial)
8 8
9 9 def [](request)
10 10 if request.path.empty? or (request.path.size == 1 and request.path[0] == '') or @allow_partial
11   - catch(:pass) do
  11 + request.passed_with = catch(:pass) do
12 12 request = request.clone
13 13 request.continue = proc { |state| destination(request) if state }
14 14 params = @param_names.nil? ? {} : Hash[@param_names.zip(request.params)]
8 lib/http_router/path.rb
... ... @@ -1,3 +1,4 @@
  1 +require 'uri'
1 2 class HttpRouter
2 3 class Path
3 4 attr_reader :route, :param_names
@@ -41,8 +42,7 @@ def url(args, options)
41 42 path = raw_url(args, options)
42 43 raise InvalidRouteException if path !~ @path_validation_regex
43 44 raise TooManyParametersException unless args.empty?
44   - uri_escape!(path)
45   - [path, options]
  45 + [URI.escape(path), options]
46 46 end
47 47
48 48 def original_path
@@ -53,9 +53,5 @@ def original_path
53 53 def raw_url(args, options)
54 54 raise UngeneratableRouteException
55 55 end
56   -
57   - def uri_escape!(s)
58   - s.to_s.gsub!(/([^:\/?\[\]\-_~\.!\$&'\(\)\*\+,;=@a-zA-Z0-9]+)/n) { "%#{$1.unpack('H2'*$1.size).join('%').upcase}" }
59   - end
60 56 end
61 57 end
2  lib/http_router/request.rb
... ... @@ -1,7 +1,7 @@
1 1 class HttpRouter
2 2 class Request
3 3 attr_reader :acceptance_test
4   - attr_accessor :path, :params, :rack_request, :extra_env, :continue
  4 + attr_accessor :path, :params, :rack_request, :extra_env, :continue, :passed_with
5 5 alias_method :rack, :rack_request
6 6 def initialize(path, rack_request, perform_call, &acceptance_test)
7 7 @rack_request, @perform_call, @acceptance_test = rack_request, perform_call, acceptance_test
3  lib/http_router/route.rb
@@ -120,6 +120,7 @@ def put; request_method('PUT'); end
120 120 def delete; request_method('DELETE'); end
121 121 def head; request_method('HEAD'); end
122 122 def options; request_method('OPTIONS'); end
  123 + def patch; request_method('PATCH'); end
123 124
124 125 def arbitrary(blk = nil, &blk2)
125 126 arbitrary_with_continue { |req, params|
@@ -273,7 +274,7 @@ def add_non_path_to_tree(node, path, names)
273 274 router.pass_on_response(response) ? throw(:pass) : throw(:success, response)
274 275 elsif req.acceptance_test
275 276 response = Response.new(req, path_obj)
276   - catch(:pass) { req.acceptance_test[response] }
  277 + req.passed_with = catch(:pass) { req.acceptance_test[response] }
277 278 throw :success, response if response.acceptance_response
278 279 else
279 280 throw :success, Response.new(req, path_obj)
1  test/helper.rb
... ... @@ -1,3 +1,4 @@
  1 +# encoding: utf-8
1 2 require 'minitest/autorun'
2 3 require 'phocus'
3 4
5 test/test_generate.rb
... ... @@ -1,3 +1,4 @@
  1 +# encoding: utf-8
1 2 class TestGenerate < MiniTest::Unit::TestCase
2 3
3 4 def test_static
@@ -86,6 +87,10 @@ def test_nil_values
86 87 assert_generate '/url', "/url(/:var)", :var => nil
87 88 end
88 89
  90 + def test_unicode
  91 + assert_generate '/%C3%A4', "/:var", :var => 'ä'
  92 + end
  93 +
89 94 def test_raise
90 95 r = router { add(':var').matching(:var => /\d+/) }
91 96 assert_raises(HttpRouter::InvalidRouteException) { router.url(r, 'asd') }
1  test/test_recognize.rb
... ... @@ -1,3 +1,4 @@
  1 +# encoding: utf-8
1 2 class TestRecognition < MiniTest::Unit::TestCase
2 3 def test_empty
3 4 assert_route router.add(''), '/'

0 comments on commit b283ade

Please sign in to comment.
Something went wrong with that request. Please try again.