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:
parent
df2226ea16
commit
805a6cc564
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user