mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix Hash#to_query edge case with html_safe string on 1.8 ruby
This commit is contained in:
parent
e314b3ff6d
commit
3a04e370e4
2 changed files with 10 additions and 1 deletions
|
@ -7,7 +7,7 @@ class Object
|
|||
# Note: This method is defined as a default implementation for all Objects for Hash#to_query to work.
|
||||
def to_query(key)
|
||||
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
|
||||
"#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}"
|
||||
"#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'abstract_unit'
|
||||
require 'active_support/ordered_hash'
|
||||
require 'active_support/core_ext/object/to_query'
|
||||
require 'active_support/core_ext/string/output_safety.rb'
|
||||
|
||||
class ToQueryTest < Test::Unit::TestCase
|
||||
def test_simple_conversion
|
||||
|
@ -11,6 +12,14 @@ class ToQueryTest < Test::Unit::TestCase
|
|||
assert_query_equal 'a%3Ab=c+d', 'a:b' => 'c d'
|
||||
end
|
||||
|
||||
def test_html_safe_parameter_key
|
||||
assert_query_equal 'a%3Ab=c+d', 'a:b'.html_safe => 'c d'
|
||||
end
|
||||
|
||||
def test_html_safe_parameter_value
|
||||
assert_query_equal 'a=%5B10%5D', 'a' => '[10]'.html_safe
|
||||
end
|
||||
|
||||
def test_nil_parameter_value
|
||||
empty = Object.new
|
||||
def empty.to_param; nil end
|
||||
|
|
Loading…
Reference in a new issue