Skip to content

Commit 805a6cc

Browse files
committed
Convert CDATA input to string before gsub'ing
Rails 3.2 API allowed arbitrary input for cdata_section; this change re-introduces the old behaviour.
1 parent df2226e commit 805a6cc

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

actionview/lib/action_view/helpers/tag_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def content_tag(name, content_or_options_with_block = nil, options = nil, escape
114114
# cdata_section("hello]]>world")
115115
# # => <![CDATA[hello]]]]><![CDATA[>world]]>
116116
def cdata_section(content)
117-
splitted = content.gsub(']]>', ']]]]><![CDATA[>')
117+
splitted = content.to_s.gsub(']]>', ']]]]><![CDATA[>')
118118
"<![CDATA[#{splitted}]]>".html_safe
119119
end
120120

actionview/test/template/tag_helper_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def test_cdata_section
9696
assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>")
9797
end
9898

99+
def test_cdata_section_with_string_conversion
100+
assert_equal "<![CDATA[]]>", cdata_section(nil)
101+
end
102+
99103
def test_cdata_section_splitted
100104
assert_equal "<![CDATA[hello]]]]><![CDATA[>world]]>", cdata_section("hello]]>world")
101105
assert_equal "<![CDATA[hello]]]]><![CDATA[>world]]]]><![CDATA[>again]]>", cdata_section("hello]]>world]]>again")

0 commit comments

Comments
 (0)