Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure `escape_javascript` return `SafeBuffer` if the incoming arg…

…ument is already html_safe
  • Loading branch information...
commit 66dbef6d791e0dfb9201eff485b0485d050e278a 1 parent fa6b12a
@sikachu sikachu authored
View
2  actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*Rails 3.1.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]
View
3  actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -18,7 +18,8 @@ module JavaScriptHelper
# $('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
View
2  actionpack/test/template/javascript_helper_test.rb
@@ -35,6 +35,8 @@ def test_escape_javascript_with_safebuffer
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
Please sign in to comment.
Something went wrong with that request. Please try again.