do not append a second slash when using
This commit is contained in:
parent
bdaafae550
commit
0b2ce7d955
@ -1,5 +1,17 @@
|
||||
## Rails 4.0.0 (unreleased) ##
|
||||
|
||||
* Do not append second slash to root_url when using `trailing_slash: true`
|
||||
Fix #8700
|
||||
|
||||
Example:
|
||||
# before
|
||||
root_url # => http://test.host//
|
||||
|
||||
# after
|
||||
root_url # => http://test.host/
|
||||
|
||||
*Yves Senn*
|
||||
|
||||
* Allow to toggle dumps on error pages.
|
||||
|
||||
*Gosha Arinich*
|
||||
|
@ -32,7 +32,11 @@ def url_for(options = {})
|
||||
params.reject! { |_,v| v.to_param.nil? }
|
||||
|
||||
result = build_host_url(options)
|
||||
result << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path)
|
||||
if options[:trailing_slash] && !path.ends_with?('/')
|
||||
result << path.sub(/(\?|\z)/) { "/" + $& }
|
||||
else
|
||||
result << path
|
||||
end
|
||||
result << "?#{params.to_query}" unless params.empty?
|
||||
result << "##{Journey::Router::Utils.escape_fragment(options[:anchor].to_param.to_s)}" if options[:anchor]
|
||||
result
|
||||
|
@ -57,13 +57,13 @@ def test_route_generation_allows_passing_non_string_values_to_generated_helper
|
||||
end
|
||||
|
||||
class MockController
|
||||
def self.build(helpers)
|
||||
def self.build(helpers, additional_options = {})
|
||||
Class.new do
|
||||
def url_options
|
||||
options = super
|
||||
define_method :url_options do
|
||||
options = super()
|
||||
options[:protocol] ||= "http"
|
||||
options[:host] ||= "test.host"
|
||||
options
|
||||
options.merge(additional_options)
|
||||
end
|
||||
|
||||
include helpers
|
||||
@ -428,8 +428,8 @@ def test_optimised_named_route_with_host
|
||||
routes.send(:pages_url)
|
||||
end
|
||||
|
||||
def setup_for_named_route
|
||||
MockController.build(rs.url_helpers).new
|
||||
def setup_for_named_route(options = {})
|
||||
MockController.build(rs.url_helpers, options).new
|
||||
end
|
||||
|
||||
def test_named_route_without_hash
|
||||
@ -456,6 +456,16 @@ def test_named_route_root_without_hash
|
||||
assert_equal("/", routes.send(:root_path))
|
||||
end
|
||||
|
||||
def test_named_route_root_with_trailing_slash
|
||||
rs.draw do
|
||||
root "hello#index"
|
||||
end
|
||||
|
||||
routes = setup_for_named_route(trailing_slash: true)
|
||||
assert_equal("http://test.host/", routes.send(:root_url))
|
||||
assert_equal("http://test.host/?foo=bar", routes.send(:root_url, foo: :bar))
|
||||
end
|
||||
|
||||
def test_named_route_with_regexps
|
||||
rs.draw do
|
||||
get 'page/:year/:month/:day/:title' => 'page#show', :as => 'article',
|
||||
|
Loading…
Reference in New Issue
Block a user