Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecate omitting the leading slash on a path arg to assert_redirect…

…ed_to
  • Loading branch information...
commit 3969148a13aaafb57c2882d25dee620e29109cd5 1 parent 1e64cdf
@jeremy jeremy authored
View
27 actionpack/lib/action_controller/assertions/response_assertions.rb
@@ -144,16 +144,25 @@ def parameterize(value)
end
def normalize_argument_to_redirection(fragment)
- after_routing = @controller.url_for(fragment)
- if after_routing =~ %r{^\w+://.*}
- after_routing
- else
- # FIXME - this should probably get removed.
- if after_routing.first != '/'
- after_routing = '/' + after_routing
+ case fragment
+ when %r{^\w[\w\d+.-]*:.*}
+ fragment
+ when String
+ if fragment =~ %r{^\w[\w\d+.-]*:.*}
+ fragment
+ else
+ if fragment !~ /^\//
+ ActiveSupport::Deprecation.warn "Omitting the leading slash on a path with assert_redirected_to is deprecated. Use '/#{fragment}' instead.", caller(2)
+ fragment = "/#{fragment}"
+ end
+ @request.protocol + @request.host_with_port + fragment
end
- @request.protocol + @request.host_with_port + after_routing
- end
+ when :back
+ raise RedirectBackError unless refer = @request.headers["Referer"]
+ refer
+ else
+ @controller.url_for(fragment)
+ end.gsub(/[\r\n]/, '')
end
end
end
View
4 actionpack/test/controller/action_pack_assertions_test.rb
@@ -458,7 +458,9 @@ def test_redirected_to_url_leading_slash
def test_redirected_to_url_no_leadling_slash
process :redirect_to_path
- assert_redirected_to 'some/path'
+ assert_deprecated /leading/ do
+ assert_redirected_to 'some/path'
+ end
end
def test_redirected_to_url_full_url
Please sign in to comment.
Something went wrong with that request. Please try again.