aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/hash_ext_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-09-17 21:31:57 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-09-17 21:31:57 +0000
commit6b68b215c2eee237248dcebbbe2c9258ebd8ca57 (patch)
tree43371fb01a91b2db164a9c8cb6518dff88a898f6 /activesupport/test/core_ext/hash_ext_test.rb
parent81d619ea0d7e936bdf5a643c8731e4b3f3746b8e (diff)
downloadrails-6b68b215c2eee237248dcebbbe2c9258ebd8ca57.tar.gz
rails-6b68b215c2eee237248dcebbbe2c9258ebd8ca57.tar.bz2
rails-6b68b215c2eee237248dcebbbe2c9258ebd8ca57.zip
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
Diffstat (limited to 'activesupport/test/core_ext/hash_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb28
1 files changed, 28 insertions, 0 deletions
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 &amp; Last Name'
+ }.stringify_keys
+
+ expected_xml = '<person><bare-string>First &amp; Last Name</bare-string><pre-escaped-string>First &amp;amp; Last Name</pre-escaped-string></person>'
+ assert_equal expected_xml, hash.to_xml(@xml_options)
+ end
+
+ def test_unescaping_from_xml
+ xml_string = '<person><bare-string>First &amp; Last Name</bare-string><pre-escaped-string>First &amp;amp; Last Name</pre-escaped-string></person>'
+ expected_hash = {
+ :bare_string => 'First & Last Name',
+ :pre_escaped_string => 'First &amp; 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 &amp; Last Name'
+ }.stringify_keys
+
+ assert_equal hash, Hash.from_xml(hash.to_xml(@xml_options))['person']
+ end
end
class QueryTest < Test::Unit::TestCase