Catch InvalidURIError on bad paths on redirect.

Handle URI::InvalidURIError errors on the redirect route method, so it
wont raise a 500 if a bad path is given.
This commit is contained in:
Arthur Neves 2015-06-16 21:03:39 +02:00
parent e60c18931c
commit e23b314945
No known key found for this signature in database
GPG Key ID: 04A390FB1E433E17
3 changed files with 19 additions and 4 deletions

@ -1,3 +1,7 @@
* Handle InvalidURIError on bad paths on redirect route.
*arthurnn*
* Deprecate passing first parameter as `Hash` and default status code for `head` method.
*Mehmet Emin İNAÇ*

@ -23,7 +23,11 @@ def call(env)
def serve(req)
req.check_path_parameters!
begin
uri = URI.parse(path(req.path_parameters, req))
rescue URI::InvalidURIError
return [ 400, {}, ['Invalid path.'] ]
end
unless uri.host
if relative_path?(uri.path)

@ -219,6 +219,13 @@ def test_X_Cascade
assert_equal 404, resp.first
end
def test_invalid_url_path
routes = Class.new { include ActionDispatch::Routing::Redirection }.new
route = routes.redirect("/foo/bar/%{id}")
resp = route.serve(rails_env({ 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/foo/(function(){})' }))
assert_equal 400, resp.first
end
def test_clear_trailing_slash_from_script_name_on_root_unanchored_routes
route_set = Routing::RouteSet.new
mapper = Routing::Mapper.new route_set