aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-08-01 10:43:45 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-08-01 10:46:35 -0300
commit69339e54d3464c6e4193ce744f975fd52b348449 (patch)
tree13c24ca75710c2ee442340e12de85fcdafa124fd
parent4e00ac3ca46ae78af3d5385bb2fec4ff480d3e29 (diff)
downloadrails-69339e54d3464c6e4193ce744f975fd52b348449.tar.gz
rails-69339e54d3464c6e4193ce744f975fd52b348449.tar.bz2
rails-69339e54d3464c6e4193ce744f975fd52b348449.zip
Fix `current_page?` when the URL contains escaped characters
In some cases webservers like nginx send the escaped characters lowercased to the Rails application. The current_page? helper was comparing the escaped strings that are different since Ruby escapes the URL using uppercased characters.
-rw-r--r--actionview/CHANGELOG.md5
-rw-r--r--actionview/lib/action_view/helpers/url_helper.rb4
-rw-r--r--actionview/test/template/url_helper_test.rb13
3 files changed, 20 insertions, 2 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index b961dce4d1..b45d5bf1e0 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Fix `current_page?` when the URL contains escaped characters and the
+ original URL is using the hexdecimal lowercased.
+
+ *Rafael Mendonça França*
+
* Fix `text_area` to behave like `text_field` when `nil` is given as
value.
diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb
index a4f04b0b3b..6bfcfad60a 100644
--- a/actionview/lib/action_view/helpers/url_helper.rb
+++ b/actionview/lib/action_view/helpers/url_helper.rb
@@ -536,9 +536,9 @@ module ActionView
request_uri = url_string.index("?") ? request.fullpath : request.path
if url_string =~ /^\w+:\/\//
- url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}"
+ URI.unescape(url_string) == URI.unescape("#{request.protocol}#{request.host_with_port}#{request_uri}")
else
- url_string == request_uri
+ URI.unescape(url_string) == URI.unescape(request_uri)
end
end
diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb
index 851ea8796f..9d9bd01de0 100644
--- a/actionview/test/template/url_helper_test.rb
+++ b/actionview/test/template/url_helper_test.rb
@@ -17,6 +17,7 @@ class UrlHelperTest < ActiveSupport::TestCase
get "/" => "foo#bar"
get "/other" => "foo#other"
get "/article/:id" => "foo#article", :as => :article
+ get "/category/:category" => "foo#category"
end
include ActionView::Helpers::UrlHelper
@@ -401,6 +402,18 @@ class UrlHelperTest < ActiveSupport::TestCase
assert !current_page?('/events')
end
+ def test_current_page_with_escaped_params
+ @request = request_for_url("/category/administra%c3%a7%c3%a3o")
+
+ assert current_page?(controller: 'foo', action: 'category', category: 'administração')
+ end
+
+ def test_current_page_with_double_escaped_params
+ @request = request_for_url("/category/administra%c3%a7%c3%a3o?callback_url=http%3a%2f%2fexample.com%2ffoo")
+
+ assert current_page?(controller: 'foo', action: 'category', category: 'administração', callback_url: 'http://example.com/foo')
+ end
+
def test_link_unless_current
@request = request_for_url("/")