Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 805a6cc56469ae50803e922e09e2b9867daff1dd 1 parent df2226e
@carpodaster carpodaster authored
View
2  actionview/lib/action_view/helpers/tag_helper.rb
@@ -114,7 +114,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 actionview/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.