Skip to content
This repository
Browse code

Fixed regex in redirect_to to fully support URI schemes [#1247 state:…

…committed]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information...
commit 47b4fa4a621ee48ab17545b1e9fb38efef53b28e 1 parent ef53d91
Seth Fitzsimmons authored October 30, 2008 dhh committed October 30, 2008
2  actionpack/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *2.2.1 [RC2 or 2.2 final]*
2 2
 
  3
+* Fixed regex in redirect_to to fully support URI schemes #1247 [Seth Fitzsimmons]
  4
+
3 5
 * Fixed bug with asset timestamping when using relative_url_root #1265 [Joe Goldwasser]
4 6
 
5 7
 
5  actionpack/lib/action_controller/base.rb
@@ -1053,7 +1053,10 @@ def redirect_to(options = {}, response_status = {}) #:doc:
1053 1053
         logger.info("Redirected to #{options}") if logger && logger.info?
1054 1054
 
1055 1055
         case options
1056  
-          when %r{^\w+://.*}
  1056
+          # The scheme name consist of a letter followed by any combination of
  1057
+          # letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
  1058
+          # characters; and is terminated by a colon (":").
  1059
+          when %r{^\w[\w\d+.-]*:.*}
1057 1060
             redirect_to_full_url(options, status)
1058 1061
           when String
1059 1062
             redirect_to_full_url(request.protocol + request.host_with_port + options, status)
10  actionpack/test/controller/redirect_test.rb
@@ -73,6 +73,10 @@ def redirect_to_url_with_unescaped_query_string
73 73
     redirect_to "http://dev.rubyonrails.org/query?status=new"
74 74
   end
75 75
 
  76
+  def redirect_to_url_with_complex_scheme
  77
+    redirect_to "x-test+scheme.complex:redirect"
  78
+  end
  79
+
76 80
   def redirect_to_back
77 81
     redirect_to :back
78 82
   end
@@ -198,6 +202,12 @@ def test_redirect_to_url_with_unescaped_query_string
198 202
     assert_redirected_to "http://dev.rubyonrails.org/query?status=new"
199 203
   end
200 204
 
  205
+  def test_redirect_to_url_with_complex_scheme
  206
+    get :redirect_to_url_with_complex_scheme
  207
+    assert_response :redirect
  208
+    assert_equal "x-test+scheme.complex:redirect", redirect_to_url
  209
+  end
  210
+
201 211
   def test_redirect_to_back
202 212
     @request.env["HTTP_REFERER"] = "http://www.example.com/coming/from"
203 213
     get :redirect_to_back

0 notes on commit 47b4fa4

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