Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'url-for-params'

Fix error when using a non-hash query argument named "params" in `url_for`.

Before:

    url_for(params: "") # => undefined method `reject!' for "":String

After:

    url_for(params: "") # => http://www.example.com?params=`

Closes #8233
  • Loading branch information...
commit 03ef833b804fe17ff834ac957a300d45bbb24fab 2 parents bba8fc4 + ce60672
@carlosantoniodasilva carlosantoniodasilva authored
View
12 actionpack/CHANGELOG.md
@@ -1,5 +1,17 @@
## Rails 4.0.0 (unreleased) ##
+* Fix error when using a non-hash query argument named "params" in `url_for`.
+
+ Before:
+
+ url_for(params: "") # => undefined method `reject!' for "":String
+
+ After:
+
+ url_for(params: "") # => http://www.example.com?params=
+
+ *tumayun + Carlos Antonio da Silva*
+
* Render every partial with a new `ActionView::PartialRenderer`. This resolves
issues when rendering nested partials.
Fix #8197
View
2  actionpack/lib/action_dispatch/http/url.rb
@@ -28,7 +28,7 @@ def url_for(options = {})
path = options.delete(:script_name).to_s.chomp("/")
path << options.delete(:path).to_s
- params = options[:params] || {}
+ params = options[:params].is_a?(Hash) ? options[:params] : options.slice(:params)
params.reject! { |_,v| v.to_param.nil? }
result = build_host_url(options)
View
4 actionpack/test/dispatch/request_test.rb
@@ -3,7 +3,7 @@
class RequestTest < ActiveSupport::TestCase
def url_for(options = {})
- options.reverse_merge!(:host => 'www.example.com')
+ options = { host: 'www.example.com' }.merge!(options)
ActionDispatch::Http::URL.url_for(options)
end
@@ -25,6 +25,8 @@ def url_for(options = {})
assert_equal 'http://www.example.com/', url_for(:trailing_slash => true)
assert_equal 'http://dhh:supersecret@www.example.com', url_for(:user => 'dhh', :password => 'supersecret')
assert_equal 'http://www.example.com?search=books', url_for(:params => { :search => 'books' })
+ assert_equal 'http://www.example.com?params=', url_for(:params => '')
+ assert_equal 'http://www.example.com?params=1', url_for(:params => 1)
end
test "remote ip" do
Please sign in to comment.
Something went wrong with that request. Please try again.