From 32dc2507ca1cfba16d685d442c9d8baff8e0bbb7 Mon Sep 17 00:00:00 2001 From: Johannes Barre Date: Wed, 16 Feb 2011 19:23:45 +0100 Subject: [PATCH] Don't escape ? and / in the anchor with url_for --- .../lib/action_dispatch/routing/route_set.rb | 2 +- actionpack/test/controller/url_for_test.rb | 4 ++-- actionpack/test/controller/url_rewriter_test.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 2ace455..27d1def 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -482,7 +482,7 @@ module ActionDispatch # ROUTES TODO: This can be called directly, so script_name should probably be set in the routes rewritten_url << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path) - rewritten_url << "##{Rack::Mount::Utils.escape_uri(options[:anchor].to_param.to_s)}" if options[:anchor] + rewritten_url << "##{URI.escape(options[:anchor].to_param.to_s)}" if options[:anchor] rewritten_url end diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb index 71a4a43..4e3eb56 100644 --- a/actionpack/test/controller/url_for_test.rb +++ b/actionpack/test/controller/url_for_test.rb @@ -41,8 +41,8 @@ module AbstractController end def test_anchor_should_not_escape_safe_pchar - assert_equal('/c/a#name=user&email=user@domain.com', - W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => Struct.new(:to_param).new('name=user&email=user@domain.com')) + assert_equal('/c/a#?name=user&email=user@domain.com&path=/articles/5', + W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => Struct.new(:to_param).new('?name=user&email=user@domain.com&path=/articles/5')) ) end diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index a8d7b75..f217400 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -67,8 +67,8 @@ class UrlRewriterTests < ActionController::TestCase def test_anchor_should_be_cgi_escaped assert_equal( - 'http://test.host/c/a/i#anc%2Fhor', - @rewriter.rewrite(@routes, :controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anc/hor')) + 'http://test.host/c/a/i#anc%23hor', + @rewriter.rewrite(@routes, :controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anc#hor')) ) end -- 1.7.4