Permalink
Browse files

split CDATA end token in cdata_section helper

  • Loading branch information...
1 parent 0274112 commit 16df67b1486d0651494a27d77f8e0469f4f1563f @lest lest committed Apr 30, 2012
Showing with 10 additions and 1 deletion.
  1. +5 −1 actionpack/lib/action_view/helpers/tag_helper.rb
  2. +5 −0 actionpack/test/template/tag_helper_test.rb
View
6 actionpack/lib/action_view/helpers/tag_helper.rb
@@ -109,8 +109,12 @@ def content_tag(name, content_or_options_with_block = nil, options = nil, escape
#
# cdata_section(File.read("hello_world.txt"))
# # => <![CDATA[<hello from a text file]]>
+ #
+ # cdata_section("hello]]>world")
+ # # => <![CDATA[hello]]]]><![CDATA[>world]]>
def cdata_section(content)
- "<![CDATA[#{content}]]>".html_safe
+ splitted = content.gsub(']]>', ']]]]><![CDATA[>')
+ "<![CDATA[#{splitted}]]>".html_safe
end
# Returns an escaped version of +html+ without affecting existing escaped entities.
View
5 actionpack/test/template/tag_helper_test.rb
@@ -91,6 +91,11 @@ def test_cdata_section
assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>")
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")
+ end
+
def test_escape_once
assert_equal '1 &lt; 2 &amp; 3', escape_once('1 < 2 &amp; 3')
end

0 comments on commit 16df67b

Please sign in to comment.