Permalink
Browse files

Filter params that return nil for to_param

  • Loading branch information...
1 parent 824107b commit 8dab7e514631407cc6473baf16bf6780daf5c628 @pixeltrix pixeltrix committed Mar 9, 2011
View
@@ -1,5 +1,7 @@
*Rails 3.0.6 (unreleased)*
+* URL parameters which return nil for to_param are now removed from the query string [Andrew White]
+
* Don't allow i18n to change the minor version, version now set to ~> 0.5.0 [Santiago Pastorino]
* Make TranslationHelper#translate use the :rescue_format option in I18n 0.5.0 [Sven Fuchs]
@@ -397,7 +397,7 @@ def generate
raise_routing_error unless path
- params.reject! {|k,v| !v }
+ params.reject! {|k,v| !v.to_param}
return [path, params.keys] if @extras
@@ -130,7 +130,6 @@ def remote_function(options)
"new Ajax.Updater(#{update}, "
url_options = options[:url]
- url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash)
function << "'#{html_escape(escape_javascript(url_for(url_options)))}'"
function << ", #{javascript_options})"
@@ -277,6 +277,14 @@ def test_with_hash_with_indifferent_access
assert_equal("/c/a", W.new.url_for(HashWithIndifferentAccess.new('controller' => 'c', 'action' => 'a', 'only_path' => true)))
end
+ def test_url_params_with_nil_to_param_are_not_in_url
+ assert_equal("/c/a", W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :id => Struct.new(:to_param).new(nil)))
+ end
+
+ def test_false_url_params_are_not_included_in_query
+ assert_equal("/c/a", W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :show => false))
+ end
+
private
def extract_params(url)
url.split('?', 2).last.split('&').sort

0 comments on commit 8dab7e5

Please sign in to comment.