Skip to content
Browse files

added passed_with support, remove uri_escape

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

0 comments on commit b283ade

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