<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -172,7 +172,7 @@ module ActionController
         path = rewrite_path(options)
         rewritten_url &lt;&lt; ActionController::Base.relative_url_root.to_s unless options[:skip_relative_url_root]
         rewritten_url &lt;&lt; (options[:trailing_slash] ? path.sub(/\?|\z/) { &quot;/&quot; + $&amp; } : path)
-        rewritten_url &lt;&lt; &quot;##{options[:anchor]}&quot; if options[:anchor]
+        rewritten_url &lt;&lt; &quot;##{CGI.escape(options[:anchor].to_param.to_s)}&quot; if options[:anchor]
 
         rewritten_url
       end</diff>
      <filename>actionpack/lib/action_controller/routing/generation/url_rewriter.rb</filename>
    </modified>
    <modified>
      <diff>@@ -46,6 +46,20 @@ class UrlRewriterTests &lt; ActionController::TestCase
     )
   end
 
+  def test_anchor_should_call_to_param
+    assert_equal(
+      'http://test.host/c/a/i#anchor',
+      @rewriter.rewrite(:controller =&gt; 'c', :action =&gt; 'a', :id =&gt; 'i', :anchor =&gt; 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 =&gt; 'c', :action =&gt; 'a', :id =&gt; 'i', :anchor =&gt; Struct.new(:to_param).new('anc/hor'))
+    )
+  end
+
   def test_overwrite_params
     @params[:controller] = 'hi'
     @params[:action] = 'bye'
@@ -110,6 +124,18 @@ class UrlWriterTests &lt; ActionController::TestCase
     )
   end
 
+  def test_anchor_should_call_to_param
+    assert_equal('/c/a#anchor',
+      W.new.url_for(:only_path =&gt; true, :controller =&gt; 'c', :action =&gt; 'a', :anchor =&gt; 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 =&gt; true, :controller =&gt; 'c', :action =&gt; 'a', :anchor =&gt; Struct.new(:to_param).new('anc/hor'))
+    )
+  end
+
   def test_default_host
     add_host!
     assert_equal('http://www.basecamphq.com/c/a/i',</diff>
      <filename>actionpack/test/controller/url_rewriter_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>cc9af20da7af98464ece18d4abc6a22ef3f00b5d</id>
    </parent>
  </parents>
  <author>
    <name>Jeffrey Hardy</name>
    <login>packagethief</login>
    <email>packagethief@gmail.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/05b529ca57f75ce64540b9d34597e0c3bfe1fca7</url>
  <id>05b529ca57f75ce64540b9d34597e0c3bfe1fca7</id>
  <committed-date>2009-08-26T14:11:26-07:00</committed-date>
  <authored-date>2009-06-02T10:28:44-07:00</authored-date>
  <message>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 &lt;jeremy@bitsweat.net&gt;</message>
  <tree>d1f751066283ba20581ab73c4f006872fcbcc393</tree>
  <committer>
    <name>Jeremy Kemper</name>
    <login>jeremy</login>
    <email>jeremy@bitsweat.net</email>
  </committer>
</commit>
