diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-06-09 11:37:06 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-06-09 11:37:06 -0700 |
commit | d0a1e37d70abc48408ed6bc087bd757adae6eee2 (patch) | |
tree | 89783214af4fbf92f5ce9606c31804af65692faf | |
parent | 834bebf9cc5acbf2c6662d1e5458a2726d305341 (diff) | |
parent | 8c8652c37f6f6969ce48d579a8c9a8ff668f995a (diff) | |
download | rails-d0a1e37d70abc48408ed6bc087bd757adae6eee2.tar.gz rails-d0a1e37d70abc48408ed6bc087bd757adae6eee2.tar.bz2 rails-d0a1e37d70abc48408ed6bc087bd757adae6eee2.zip |
Merge pull request #1609 from sikachu/master-javascript
Make sure `escape_javascript` return `SafeBuffer` if the incoming argumen
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/javascript_helper.rb | 3 | ||||
-rw-r--r-- | actionpack/test/template/javascript_helper_test.rb | 2 |
3 files changed, 6 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 42baf6f45f..5314dcc193 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.2.0 (unreleased)* +* 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] * Brought back alternative convention for namespaced models in i18n [thoefer] diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 8a6f2e84be..4484390fde 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -18,7 +18,8 @@ module ActionView # $('some_element').replaceWith('<%=j render 'some/element_template' %>'); def escape_javascript(javascript) if javascript - javascript.gsub(/(\\|<\/|\r\n|[\n\r"'])/) {|match| JS_ESCAPE_MAP[match] } + result = javascript.gsub(/(\\|<\/|\r\n|[\n\r"'])/) {|match| JS_ESCAPE_MAP[match] } + javascript.html_safe? ? result.html_safe : result else '' end diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index 15bd6b4c47..dd8b7b7cd5 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -35,6 +35,8 @@ class JavaScriptHelperTest < ActionView::TestCase expect = %(\\'quoted\\' \\"double-quoted\\" new-line:\\n <\\/closed>) assert_equal expect, escape_javascript(given) assert_equal expect, escape_javascript(ActiveSupport::SafeBuffer.new(given)) + assert_instance_of String, escape_javascript(given) + assert_instance_of ActiveSupport::SafeBuffer, escape_javascript(ActiveSupport::SafeBuffer.new(given)) end def test_button_to_function |