Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove side effects on :controller option in #url_for #6375

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion actionpack/lib/action_dispatch/routing/route_set.rb
Expand Up @@ -412,7 +412,7 @@ def initialize(options, recall, set, extras = false)
normalize_options!
normalize_controller_action_id!
use_relative_controller!
controller.sub!(%r{^/}, '') if controller
normalize_controller_leading_slash
handle_nil_action!
end

Expand Down Expand Up @@ -478,6 +478,11 @@ def use_relative_controller!
end
end

# remove leading slashes from the controller: '/foo/bar' becomes 'foo/bar'
def normalize_controller_leading_slash
@controller = @options[:controller] = controller.sub(%r{^/}, '') if controller
end

# This handles the case of :action => nil being explicitly passed.
# It is identical to :action => "index"
def handle_nil_action!
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/controller/url_for_test.rb
Expand Up @@ -333,6 +333,14 @@ def test_false_url_params_are_included_in_query
assert_equal("/c/a?show=false", W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :show => false))
end

def test_url_for_has_no_side_effects
add_host!

controller_name = '/C'
assert_equal('http://www.basecamphq.com/C', W.new.url_for(:controller => controller_name))
assert_equal('/C', controller_name)
end

private
def extract_params(url)
url.split('?', 2).last.split('&').sort
Expand Down