Convert CDATA input to string before gsub'ing

Rails 3.2 API allowed arbitrary input for cdata_section;
this change re-introduces the old behaviour.
This commit is contained in:
Carsten Zimmermann 2013-10-29 18:17:57 +01:00
parent df2226ea16
commit 805a6cc564
2 changed files with 5 additions and 1 deletions

@ -114,7 +114,7 @@ def content_tag(name, content_or_options_with_block = nil, options = nil, escape
# cdata_section("hello]]>world")
# # => <![CDATA[hello]]]]><![CDATA[>world]]>
def cdata_section(content)
splitted = content.gsub(']]>', ']]]]><![CDATA[>')
splitted = content.to_s.gsub(']]>', ']]]]><![CDATA[>')
"<![CDATA[#{splitted}]]>".html_safe
end

@ -96,6 +96,10 @@ def test_cdata_section
assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>")
end
def test_cdata_section_with_string_conversion
assert_equal "<![CDATA[]]>", cdata_section(nil)
end
def test_cdata_section_splitted
assert_equal "<![CDATA[hello]]]]><![CDATA[>world]]>", cdata_section("hello]]>world")
assert_equal "<![CDATA[hello]]]]><![CDATA[>world]]]]><![CDATA[>again]]>", cdata_section("hello]]>world]]>again")