mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #8704 from senny/remove_regexp_global_from_url_for
replace regexp global in #url_for
This commit is contained in:
commit
9d023c87de
2 changed files with 9 additions and 2 deletions
|
@ -32,8 +32,12 @@ module ActionDispatch
|
||||||
params.reject! { |_,v| v.to_param.nil? }
|
params.reject! { |_,v| v.to_param.nil? }
|
||||||
|
|
||||||
result = build_host_url(options)
|
result = build_host_url(options)
|
||||||
if options[:trailing_slash] && !path.ends_with?('/')
|
if options[:trailing_slash]
|
||||||
result << path.sub(/(\?|\z)/) { "/" + $& }
|
if path.include?('?')
|
||||||
|
result << path.sub(/\?/, '/\&')
|
||||||
|
else
|
||||||
|
result << path.sub(/[^\/]\z|\A\z/, '\&/')
|
||||||
|
end
|
||||||
else
|
else
|
||||||
result << path
|
result << path
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,6 +13,9 @@ class RequestTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
assert_equal '/books', url_for(:only_path => true, :path => '/books')
|
assert_equal '/books', url_for(:only_path => true, :path => '/books')
|
||||||
|
|
||||||
|
assert_equal 'http://www.example.com/books/?q=code', url_for(trailing_slash: true, path: '/books?q=code')
|
||||||
|
assert_equal 'http://www.example.com/books/?spareslashes=////', url_for(trailing_slash: true, path: '/books?spareslashes=////')
|
||||||
|
|
||||||
assert_equal 'http://www.example.com', url_for
|
assert_equal 'http://www.example.com', url_for
|
||||||
assert_equal 'http://api.example.com', url_for(:subdomain => 'api')
|
assert_equal 'http://api.example.com', url_for(:subdomain => 'api')
|
||||||
assert_equal 'http://example.com', url_for(:subdomain => false)
|
assert_equal 'http://example.com', url_for(:subdomain => false)
|
||||||
|
|
Loading…
Reference in a new issue