提交 6b68b215 编写于 作者: J Jeremy Kemper

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
上级 81d619ea
*SVN*
* Hash#to_xml doesn't double-unescape. #8806 [Ezran]
* Added Array#rand #9170 [norbert]. Examples:
[].rand # => nil
......
......@@ -169,7 +169,7 @@ def typecast_xml_value(value)
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 @@ def typecast_xml_value(value)
end
end
def translate_xml_entities(value)
value.gsub(/&lt;/, "<").
gsub(/&gt;/, ">").
gsub(/&quot;/, '"').
gsub(/&apos;/, "'").
gsub(/&amp;/, "&")
end
def undasherize_keys(params)
case params.class.to_s
when "Hash"
......
......@@ -643,6 +643,34 @@ def test_empty_string_works_for_typecast_xml_value
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册