mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
split CDATA end token in cdata_section helper
This commit is contained in:
parent
02741121be
commit
16df67b148
2 changed files with 10 additions and 1 deletions
|
@ -109,8 +109,12 @@ module ActionView
|
|||
#
|
||||
# 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.
|
||||
|
|
|
@ -91,6 +91,11 @@ class TagHelperTest < ActionView::TestCase
|
|||
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 < 2 & 3', escape_once('1 < 2 & 3')
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue