diff options
author | Arthur Nogueira Neves <github@arthurnn.com> | 2015-11-26 16:10:46 -0500 |
---|---|---|
committer | Arthur Nogueira Neves <github@arthurnn.com> | 2015-11-26 16:10:46 -0500 |
commit | 9afb0b9c432f6987a59b44c2fff15785b5fd5784 (patch) | |
tree | 91c94f15998f1038ad8637eab23b5dd434c5a44a /actionpack | |
parent | 52141d365805f6433c9adf272aa6c19e3049147e (diff) | |
parent | e6e056c2c141ec94eb8e79a30ee766f77fdaf30d (diff) | |
download | rails-9afb0b9c432f6987a59b44c2fff15785b5fd5784.tar.gz rails-9afb0b9c432f6987a59b44c2fff15785b5fd5784.tar.bz2 rails-9afb0b9c432f6987a59b44c2fff15785b5fd5784.zip |
Merge pull request #21241 from pdg137/master
In url_for, never append ? when the query string is empty anyway.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 4 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/url.rb | 3 | ||||
-rw-r--r-- | actionpack/test/dispatch/url_generation_test.rb | 7 |
3 files changed, 13 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 40f447ada7..a62f655dc2 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,7 @@ +* In url_for, never append a question mark to the URL when the query string + is empty anyway. (It used to do that when called like `url_for(controller: + 'x', action: 'y', q: {})`.) + * Catch invalid UTF-8 querystring values and respond with BadRequest Check querystring params for invalid UTF-8 characters, and raise an diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index 92b10b6d3b..37f41ae988 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -81,7 +81,8 @@ module ActionDispatch def add_params(path, params) params = { params: params } unless params.is_a?(Hash) params.reject! { |_,v| v.to_param.nil? } - path << "?#{params.to_query}" unless params.empty? + query = params.to_query + path << "?#{query}" unless query.empty? end def add_anchor(path, anchor) diff --git a/actionpack/test/dispatch/url_generation_test.rb b/actionpack/test/dispatch/url_generation_test.rb index fd4ede4d1b..8c9782bb90 100644 --- a/actionpack/test/dispatch/url_generation_test.rb +++ b/actionpack/test/dispatch/url_generation_test.rb @@ -129,6 +129,13 @@ module TestUrlGeneration ) end + test "generating URLS with empty querystring" do + assert_equal "/bars.json", bars_path( + a: {}, + format: 'json' + ) + end + end end |