From 3be52df49e90f153f2930073ccc8064e55056a3d Mon Sep 17 00:00:00 2001 From: Seth Fitzsimmons Date: Thu, 30 Oct 2008 12:03:47 -0700 Subject: [PATCH] Fixed regex in redirect_to to fully support URI schemes. --- actionpack/lib/action_controller/base.rb | 5 ++++- actionpack/test/controller/redirect_test.rb | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 2cff05d..e9429d3 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -1053,7 +1053,10 @@ module ActionController #:nodoc: logger.info("Redirected to #{options}") if logger && logger.info? case options - when %r{^\w+://.*} + # The scheme name consist of a letter followed by any combination of + # letters, digits, and the plus ("+"), period ("."), or hyphen ("-") + # characters; and is terminated by a colon (":"). + when %r{^\w[\w\d+.-]*:.*} redirect_to_full_url(options, status) when String redirect_to_full_url(request.protocol + request.host_with_port + options, status) diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 2f8bf7b..c55307d 100644 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -73,6 +73,10 @@ class RedirectController < ActionController::Base redirect_to "http://dev.rubyonrails.org/query?status=new" end + def redirect_to_url_with_complex_scheme + redirect_to "x-test+scheme.complex:redirect" + end + def redirect_to_back redirect_to :back end @@ -198,6 +202,12 @@ class RedirectTest < Test::Unit::TestCase assert_redirected_to "http://dev.rubyonrails.org/query?status=new" end + def test_redirect_to_url_with_complex_scheme + get :redirect_to_url_with_complex_scheme + assert_response :redirect + assert_equal "x-test+scheme.complex:redirect", redirect_to_url + end + def test_redirect_to_back @request.env["HTTP_REFERER"] = "http://www.example.com/coming/from" get :redirect_to_back -- 1.5.6.5