From ef89331f0a397bc88d6e27480aa7562db70550f7 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sat, 25 Jun 2016 11:29:39 +0800 Subject: [PATCH] Fix ActionView::Helpers#current_page? with issue in https://github.com/rails/rails/issues/19472 --- actionview/lib/action_view/helpers/url_helper.rb | 2 ++ actionview/test/template/url_helper_test.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index 11c7daf4da..fb6426b997 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -548,6 +548,8 @@ module ActionView request_uri = url_string.index("?") ? request.fullpath : request.path request_uri = URI.parser.unescape(request_uri).force_encoding(Encoding::BINARY) + url_string.chomp!("/") if url_string.start_with?("/") && url_string != "/" + if url_string =~ /^\w+:\/\// url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}" else diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index ab56d80de3..6060ea2f1e 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -503,6 +503,12 @@ class UrlHelperTest < ActiveSupport::TestCase assert current_page?(controller: 'foo', action: 'category', category: 'administraĆ§Ć£o', callback_url: 'http://example.com/foo') end + def test_current_page_with_trailing_slash + @request = request_for_url("/posts") + + assert current_page?("/posts/") + end + def test_link_unless_current @request = request_for_url("/")