Skip to content

Commit

Permalink
Make sure escape_javascript return SafeBuffer if the incoming arg…
Browse files Browse the repository at this point in the history
…ument is already html_safe
  • Loading branch information
sikachu committed Jun 9, 2011
1 parent fa6b12a commit 66dbef6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*Rails 3.1.0 (unreleased)* *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] * Fix escape_js to work correctly with the new SafeBuffer restriction [Paul Gallagher]


* Brought back alternative convention for namespaced models in i18n [thoefer] * Brought back alternative convention for namespaced models in i18n [thoefer]
Expand Down
3 changes: 2 additions & 1 deletion actionpack/lib/action_view/helpers/javascript_helper.rb
Expand Up @@ -18,7 +18,8 @@ module JavaScriptHelper
# $('some_element').replaceWith('<%=j render 'some/element_template' %>'); # $('some_element').replaceWith('<%=j render 'some/element_template' %>');
def escape_javascript(javascript) def escape_javascript(javascript)
if 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 else
'' ''
end end
Expand Down
2 changes: 2 additions & 0 deletions actionpack/test/template/javascript_helper_test.rb
Expand Up @@ -35,6 +35,8 @@ def test_escape_javascript_with_safebuffer
expect = %(\\'quoted\\' \\"double-quoted\\" new-line:\\n <\\/closed>) expect = %(\\'quoted\\' \\"double-quoted\\" new-line:\\n <\\/closed>)
assert_equal expect, escape_javascript(given) assert_equal expect, escape_javascript(given)
assert_equal expect, escape_javascript(ActiveSupport::SafeBuffer.new(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 end


def test_button_to_function def test_button_to_function
Expand Down

0 comments on commit 66dbef6

Please sign in to comment.