Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

Convert CDATA input to string before gsub'ing
  • Loading branch information...
commit 11088d34175d4ce386faaecccf0b5aa71c6caceb 1 parent 91684fb
@rafaelfranca rafaelfranca authored
View
2  actionpack/lib/action_view/helpers/tag_helper.rb
@@ -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
View
4 actionpack/test/template/tag_helper_test.rb
@@ -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")
Please sign in to comment.
Something went wrong with that request. Please try again.