Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

replace regexp global in #url_for

  • Loading branch information...
commit 19e9e67f95aa2f173e73ba11b22370c31b922103 1 parent 555cb0a
@senny senny authored senny committed
View
8 actionpack/lib/action_dispatch/http/url.rb
@@ -32,8 +32,12 @@ def url_for(options = {})
params.reject! { |_,v| v.to_param.nil? }
result = build_host_url(options)
- if options[:trailing_slash] && !path.ends_with?('/')
- result << path.sub(/(\?|\z)/) { "/" + $& }
+ if options[:trailing_slash]
+ if path.include?('?')
+ result << path.sub(/\?/, '/\&')
+ else
+ result << path.sub(/[^\/]\z|\A\z/, '\&/')
+ end
else
result << path
end
View
3  actionpack/test/dispatch/request_test.rb
@@ -13,6 +13,9 @@ def url_for(options = {})
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://api.example.com', url_for(:subdomain => 'api')
assert_equal 'http://example.com', url_for(:subdomain => false)
Please sign in to comment.
Something went wrong with that request. Please try again.