Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

UrlRewriter#rewrite_url should call #to_param on the value given in :…

…anchor option, just as #url_for does

[#2746 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit 05b529ca57f75ce64540b9d34597e0c3bfe1fca7 1 parent cc9af20
@packagethief packagethief authored jeremy committed
View
2  actionpack/lib/action_controller/routing/generation/url_rewriter.rb
@@ -172,7 +172,7 @@ def rewrite_url(options)
path = rewrite_path(options)
rewritten_url << ActionController::Base.relative_url_root.to_s unless options[:skip_relative_url_root]
rewritten_url << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path)
- rewritten_url << "##{options[:anchor]}" if options[:anchor]
+ rewritten_url << "##{CGI.escape(options[:anchor].to_param.to_s)}" if options[:anchor]
rewritten_url
end
View
26 actionpack/test/controller/url_rewriter_test.rb
@@ -46,6 +46,20 @@ def test_anchor
)
end
+ def test_anchor_should_call_to_param
+ assert_equal(
+ 'http://test.host/c/a/i#anchor',
+ @rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anchor'))
+ )
+ end
+
+ def test_anchor_should_be_cgi_escaped
+ assert_equal(
+ 'http://test.host/c/a/i#anc%2Fhor',
+ @rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anc/hor'))
+ )
+ end
+
def test_overwrite_params
@params[:controller] = 'hi'
@params[:action] = 'bye'
@@ -110,6 +124,18 @@ def test_anchor
)
end
+ def test_anchor_should_call_to_param
+ assert_equal('/c/a#anchor',
+ W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => Struct.new(:to_param).new('anchor'))
+ )
+ end
+
+ def test_anchor_should_be_cgi_escaped
+ assert_equal('/c/a#anc%2Fhor',
+ W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => Struct.new(:to_param).new('anc/hor'))
+ )
+ end
+
def test_default_host
add_host!
assert_equal('http://www.basecamphq.com/c/a/i',

1 comment on commit 05b529c

@aiwilliams

The ActionView::Helpers::UrlHelper#url_for method allows for an :escape => false option. This allowed us to have unescaped :anchor options. That is lost with this change. Was that intentional?

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