Permalink
Browse files

Merge pull request #12693 from carpodaster/convert-cdata-input-to-string

Convert CDATA input to string before gsub'ing
  • Loading branch information...
1 parent 91684fb commit 11088d34175d4ce386faaecccf0b5aa71c6caceb @rafaelfranca rafaelfranca committed Oct 29, 2013
@@ -111,7 +111,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")

0 comments on commit 11088d3

Please sign in to comment.