From ff48edd442a9727a1931e6127d29340f903a1e2a Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Fri, 10 Jun 2011 18:29:52 -0400 Subject: [PATCH 1/2] Update CHANGELOG to mention the json_escape change --- actionpack/CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index ac71a397b6..5f9c8a93dd 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.1.0 (unreleased)* +* json_escape will now return a SafeBuffer string if it receives SafeBuffer string [tenderlove] + * Make sure escape_js returns SafeBuffer string if it receives SafeBuffer string [Prem Sichanugrist] * Fix escape_js to work correctly with the new SafeBuffer restriction [Paul Gallagher] From 317e7c829d4b281b4e7a96fe65960c9a2b7ba664 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Fri, 10 Jun 2011 18:22:42 -0400 Subject: [PATCH 2/2] Make sure that we don't perform in-place mutation on SafeBuffer string This will make sure `render :inline` is working. Closes #1633 --- actionpack/lib/action_view/template.rb | 3 +++ actionpack/test/template/template_test.rb | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index b99d24d281..c16588d88d 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -219,6 +219,9 @@ module ActionView method_name = self.method_name if source.encoding_aware? + # Avoid performing in-place mutation for SafeBuffer + @source = source.to_str if source.html_safe? + # Look for # encoding: *. If we find one, we'll encode the # String in that encoding, otherwise, we'll use the # default external encoding. diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 81fb34b80f..4d05fee1e3 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -173,5 +173,10 @@ class TestERBTemplate < ActiveSupport::TestCase ensure silence_warnings { Encoding.default_external = old } end + + def test_render_inline_safebuffer_should_not_raise_error + @template = new_template("Hello".html_safe) + render + end end end