From ffba8f79a2332398d4848d8987a42567001cbdf4 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Wed, 17 Jun 2015 20:17:44 +0200 Subject: [PATCH] Revert "Merge pull request #20584 from arthurnn/fix_url" This reverts commit 0b3397872582f2cf1bc6960960a6393f477c55e6, reversing changes made to 56d52e3749180e6c1dcf7166adbad967470aa78b. As pointed out on the PR, this will hide development mistakes too, which is not ideal. --- actionpack/CHANGELOG.md | 4 ---- .../lib/action_dispatch/routing/redirection.rb | 12 ++++-------- actionpack/test/journey/router_test.rb | 7 ------- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index e8ec3fad73..cb5e7516fb 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,7 +1,3 @@ -* 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Ç* diff --git a/actionpack/lib/action_dispatch/routing/redirection.rb b/actionpack/lib/action_dispatch/routing/redirection.rb index 8d965a5f8e..3c1c4fadf6 100644 --- a/actionpack/lib/action_dispatch/routing/redirection.rb +++ b/actionpack/lib/action_dispatch/routing/redirection.rb @@ -23,12 +23,8 @@ 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 - + uri = URI.parse(path(req.path_parameters, req)) + unless uri.host if relative_path?(uri.path) uri.path = "#{req.script_name}/#{uri.path}" @@ -36,7 +32,7 @@ def serve(req) uri.path = req.script_name.empty? ? "/" : req.script_name end end - + uri.scheme ||= req.scheme uri.host ||= req.host uri.port ||= req.port unless req.standard_port? @@ -128,7 +124,7 @@ def path(params, request) url_options[:script_name] = request.script_name end end - + ActionDispatch::Http::URL.url_for url_options end diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index c4bffa2f15..802fb93c69 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -219,13 +219,6 @@ 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 -- GitLab