ActionController::Routings:Routes#build_query_string doesn't support boolean params properly #4307

Closed
georgeqchen opened this Issue Jan 4, 2012 · 3 comments

Projects

None yet

3 participants

@georgeqchen

This is the current implementation from apidock,

http://apidock.com/rails/v2.3.8/ActionController/Routing/Route/build_query_string

File actionpack/lib/action_controller/routing/route.rb, line 48

  def build_query_string(hash, only_keys = nil)
    elements = []

    (only_keys || hash.keys).each do |key|
      if value = hash[key]            
        elements << value.to_query(key)
      end
    end

    elements.empty? ? '' : "?#{elements.sort * '&'}"
  end

The issue here is that if you create a url with an optional url param that is a boolean and has value = false, then the above code will neglect the url param.

For in stance, if you call:
url_for(:controller => 'users',
:action => 'new',
:host => 'www.example.com',
:activated=>false)
The expected url should be: "http://www.example.com/users/new?activated=false"
The actual url generated is: "http://www.example.com/users/new"

The error is on the line: if value = hash[key]
Instead, it should be: unless (value = hash[key]).nil?

@guilleiguaran
Member

This issue is about Rails 2.3.x ?

@georgeqchen

Yes, I am running 2.3.2. From the apidock, looks like the latest version of this file is on 2.3.8, which still has the issue.

@tenderlove
Member

Please upgrade to Rails 3.0.x and try again. Rails 2.3.x will only be released and patch in the event of security issues. Thanks!

@tenderlove tenderlove closed this Jan 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment