From 6b68b215c2eee237248dcebbbe2c9258ebd8ca57 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 17 Sep 2007 21:31:57 +0000 Subject: Hash#to_xml doesn't double-unescape. Closes #8806. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7505 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/core_ext/hash_ext_test.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'activesupport/test') 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 &amp; Last Name' + assert_equal expected_xml, hash.to_xml(@xml_options) + end + + def test_unescaping_from_xml + xml_string = 'First & Last NameFirst &amp; 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 -- cgit v1.2.3