mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
4e00ac3ca4
commit
69339e54d3
3 changed files with 20 additions and 2 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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("/")
|
||||
|
||||
|
|
Loading…
Reference in a new issue