Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

undefined method `reject!' for "":String #8233

Closed
wants to merge 2 commits into from

3 participants

@tumayun

http://ju.tao800.com/page/2?params=
http://ruby-china.org/topics?params=

undefined method `reject!' for "":String

options[:params] only Hash

@carlosantoniodasilva

Thanks, but we need some tests to ensure that behavior won't change in the future, can you add it?

@pzgz

+1, thanks.

@carlosantoniodasilva carlosantoniodasilva referenced this pull request from a commit
@carlosantoniodasilva carlosantoniodasilva Correct the use of params options when given to url_for
Merge url for tests and add changelog entry for #8233.
ce60672
@carlosantoniodasilva carlosantoniodasilva closed this pull request from a commit
@carlosantoniodasilva carlosantoniodasilva 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
03ef833
@pwnall pwnall referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
7 actionpack/lib/action_dispatch/http/url.rb
@@ -27,7 +27,12 @@ def url_for(options = {})
path << options.delete(:script_name).to_s.chomp("/")
path << options.delete(:path).to_s
- params = options[:params] || {}
+ params = if options[:params].is_a?(::Hash)
+ options[:params]
+ else
+ {}
+ end
+
params.reject! {|k,v| v.to_param.nil? }
result = build_host_url(options)
View
8 actionpack/test/dispatch/request_test.rb
@@ -800,6 +800,14 @@ def url_for(options = {})
end
end
+ test "url_for options[:params]" do
+ assert_equal 'http://www.example.com?params=', url_for(:params => '')
+ assert_equal 'http://www.example.com?params=1', url_for(:params => 1)
+ assert_equal 'http://www.example.com', url_for
+ assert_equal 'http://www.example.com', url_for(:params => {})
+ assert_equal 'http://www.example.com?name=tumayun', url_for(:params => { :name => 'tumayun' })
+ end
+
protected
def stub_request(env = {})
Something went wrong with that request. Please try again.