Merge pull request #21241 from pdg137/master
In url_for, never append ? when the query string is empty anyway.
This commit is contained in:
commit
9afb0b9c43
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue