From 805a6cc56469ae50803e922e09e2b9867daff1dd Mon Sep 17 00:00:00 2001 From: Carsten Zimmermann Date: Tue, 29 Oct 2013 18:17:57 +0100 Subject: 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. --- actionview/lib/action_view/helpers/tag_helper.rb | 2 +- actionview/test/template/tag_helper_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/actionview/lib/action_view/helpers/tag_helper.rb b/actionview/lib/action_view/helpers/tag_helper.rb index 732f35643a..11e41ec056 100644 --- a/actionview/lib/action_view/helpers/tag_helper.rb +++ b/actionview/lib/action_view/helpers/tag_helper.rb @@ -114,7 +114,7 @@ module ActionView # cdata_section("hello]]>world") # # => world]]> def cdata_section(content) - splitted = content.gsub(']]>', ']]]]>') + splitted = content.to_s.gsub(']]>', ']]]]>') "".html_safe end diff --git a/actionview/test/template/tag_helper_test.rb b/actionview/test/template/tag_helper_test.rb index 802da5d566..fb016a52de 100644 --- a/actionview/test/template/tag_helper_test.rb +++ b/actionview/test/template/tag_helper_test.rb @@ -96,6 +96,10 @@ class TagHelperTest < ActionView::TestCase assert_equal "]]>", cdata_section("") end + def test_cdata_section_with_string_conversion + assert_equal "", cdata_section(nil) + end + def test_cdata_section_splitted assert_equal "world]]>", cdata_section("hello]]>world") assert_equal "world]]]]>again]]>", cdata_section("hello]]>world]]>again") -- cgit v1.2.3