aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorPaul Grayson <paul@pololu.com>2015-08-14 15:19:56 -0700
committerPaul Grayson <paul@pololu.com>2015-10-29 17:02:13 -0700
commite6e056c2c141ec94eb8e79a30ee766f77fdaf30d (patch)
tree789818a9cc7efaa96a6f2d5e36dbbf3d81daaeb3 /actionview
parent8941831733fc56e2b1872f41c85cc48d782bb984 (diff)
downloadrails-e6e056c2c141ec94eb8e79a30ee766f77fdaf30d.tar.gz
rails-e6e056c2c141ec94eb8e79a30ee766f77fdaf30d.tar.bz2
rails-e6e056c2c141ec94eb8e79a30ee766f77fdaf30d.zip
In url_for, never append ? when the query string is empty anyway.
It used to behave like this: url_for(controller: 'x', action: 'y', q: {}) # -> "/x/y?" We previously avoided empty query strings in most cases by removing nil values, then checking whether params was empty. But as you can see above, even non-empty params can yield an empty query string. So I changed the code to just directly check whether the query string ended up empty. (To make everything more consistent, the "removing nil values" functionality should probably move to ActionPack's Hash#to_query, the place where empty hashes and arrays get removed. However, this would change a lot more behavior.)
Diffstat (limited to 'actionview')
-rw-r--r--actionview/test/template/url_helper_test.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb
index 50b7865f88..b8f4d13812 100644
--- a/actionview/test/template/url_helper_test.rb
+++ b/actionview/test/template/url_helper_test.rb
@@ -38,6 +38,10 @@ class UrlHelperTest < ActiveSupport::TestCase
assert_equal "/?a=b&c=d", url_for(hash_for(a: :b, c: :d))
end
+ def test_url_for_does_not_include_empty_hashes
+ assert_equal "/", url_for(hash_for(a: {}))
+ end
+
def test_url_for_with_back
referer = 'http://www.example.com/referer'
@controller = Struct.new(:request).new(Struct.new(:env).new("HTTP_REFERER" => referer))