diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index 7ba42a3b721f58e8167bbe0c1fdf7a9bd2427e29..2e0eb8766b6b74ca68ab1e26d04291afc364265b 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -499,7 +499,7 @@ def mail_to(email_address, name = nil, html_options = {})
# True if the current request URI was generated by the given +options+.
#
# ==== Examples
- # Let's say we're in the /shop/checkout action.
+ # Let's say we're in the /shop/checkout?order=desc action.
#
# current_page?(:action => 'process')
# # => false
@@ -507,6 +507,9 @@ def mail_to(email_address, name = nil, html_options = {})
# current_page?(:controller => 'shop', :action => 'checkout')
# # => true
#
+ # current_page?(:controller => 'shop', :action => 'checkout', :order => 'asc)
+ # # => false
+ #
# current_page?(:action => 'checkout')
# # => true
#
@@ -515,10 +518,18 @@ def mail_to(email_address, name = nil, html_options = {})
def current_page?(options)
url_string = CGI.escapeHTML(url_for(options))
request = @controller.request
+ # We ignore any extra parameters in the request_uri if the
+ # submitted url doesn't have any either. This lets the function
+ # work with things like ?order=asc
+ if url_string.index("?")
+ request_uri = request.request_uri
+ else
+ request_uri = request.request_uri.split('?').first
+ end
if url_string =~ /^\w+:\/\//
- url_string == "#{request.protocol}#{request.host_with_port}#{request.request_uri}"
+ url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}"
else
- url_string == request.request_uri
+ url_string == request_uri
end
end
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index 85e967ac1c9038c9207a307caed4dd17107eb5b6..797b74efe6f2022e760a8da77eb6346cd1d72473 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -258,6 +258,16 @@ def test_link_unless_current
assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" })
assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show")
+ @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc")
+ @controller.url = "http://www.example.com/weblog/show"
+ assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" })
+ assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show")
+
+ @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc")
+ @controller.url = "http://www.example.com/weblog/show?order=asc"
+ assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" })
+ assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show?order=asc")
+
@controller.request = RequestMock.new("http://www.example.com/weblog/show")
@controller.url = "http://www.example.com/weblog/list"
assert_equal "Listing",