diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 915b206bc7..895c1b4bab 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Hash#to_xml doesn't double-unescape. #8806 [Ezran]
+
* Added Array#rand #9170 [norbert]. Examples:
[].rand # => nil
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index d8c6852e25..97b4301bdd 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -169,7 +169,7 @@ module ActiveSupport #:nodoc:
case value.class.to_s
when 'Hash'
if value.has_key?("__content__")
- content = translate_xml_entities(value["__content__"])
+ content = value["__content__"]
if parser = XML_PARSING[value["type"]]
if parser.arity == 2
XML_PARSING[value["type"]].call(content, value)
@@ -226,14 +226,6 @@ module ActiveSupport #:nodoc:
end
end
- def translate_xml_entities(value)
- value.gsub(/</, "<").
- gsub(/>/, ">").
- gsub(/"/, '"').
- gsub(/'/, "'").
- gsub(/&/, "&")
- end
-
def undasherize_keys(params)
case params.class.to_s
when "Hash"
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 17bfb3a92c..0d19ed742a 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -643,6 +643,34 @@ class HashToXmlTest < Test::Unit::TestCase
Hash.send(:typecast_xml_value, "")
end
end
+
+ def test_escaping_to_xml
+ hash = {
+ :bare_string => 'First & Last Name',
+ :pre_escaped_string => 'First & Last Name'
+ }.stringify_keys
+
+ expected_xml = 'First & Last NameFirst & Last Name'
+ assert_equal expected_xml, hash.to_xml(@xml_options)
+ end
+
+ def test_unescaping_from_xml
+ xml_string = 'First & Last NameFirst & Last Name'
+ expected_hash = {
+ :bare_string => 'First & Last Name',
+ :pre_escaped_string => 'First & Last Name'
+ }.stringify_keys
+ assert_equal expected_hash, Hash.from_xml(xml_string)['person']
+ end
+
+ def test_roundtrip_to_xml_from_xml
+ hash = {
+ :bare_string => 'First & Last Name',
+ :pre_escaped_string => 'First & Last Name'
+ }.stringify_keys
+
+ assert_equal hash, Hash.from_xml(hash.to_xml(@xml_options))['person']
+ end
end
class QueryTest < Test::Unit::TestCase