Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make sure `escape_javascript` return `SafeBuffer` if the incoming argumen #1611

Merged
merged 1 commit into from

2 participants

@sikachu
Collaborator

Make sure escape_javascript return SafeBuffer if the incoming argument is already html_safe

@tenderlove tenderlove merged commit b6a2157 into rails:3-0-stable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 9, 2011
  1. @sikachu

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

    sikachu authored
    …ument is already html_safe
This page is out of date. Refresh to see the latest.
View
2  actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*Rails 3.0.9 (unreleased)*
+* Make sure escape_js returns SafeBuffer string if it receives SafeBuffer string [Prem Sichanugrist]
+
* Fix text helpers to work correctly with the new SafeBuffer restriction [Paul Gallagher, Arun Agrawal, Prem Sichanugrist]
View
3  actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -49,7 +49,8 @@ module JavaScriptHelper
# Escape carrier returns and single and double quotes for JavaScript segments.
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
@@ -36,6 +36,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
Something went wrong with that request. Please try again.