diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index 23777721f6..f7afa48256 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -109,8 +109,12 @@ module ActionView # # cdata_section(File.read("hello_world.txt")) # # => + # + # cdata_section("hello]]>world") + # # => world]]> def cdata_section(content) - "".html_safe + splitted = content.gsub(']]>', ']]]]>') + "".html_safe end # Returns an escaped version of +html+ without affecting existing escaped entities. diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb index 32b33b4a55..7161d107b3 100644 --- a/actionpack/test/template/tag_helper_test.rb +++ b/actionpack/test/template/tag_helper_test.rb @@ -91,6 +91,11 @@ class TagHelperTest < ActionView::TestCase assert_equal "]]>", cdata_section("") end + def test_cdata_section_splitted + assert_equal "world]]>", cdata_section("hello]]>world") + assert_equal "world]]]]>again]]>", cdata_section("hello]]>world]]>again") + end + def test_escape_once assert_equal '1 < 2 & 3', escape_once('1 < 2 & 3') end