mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added JavascriptHelper#escape_javascript as a public method (was private) and made it escape both single and double quotes and new lines #940 [mortonda@dgrmm.net]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1002 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
7a6a923f98
commit
3fe9d8ac35
3 changed files with 15 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Added JavascriptHelper#escape_javascript as a public method (was private) and made it escape both single and double quotes and new lines #940 [mortonda@dgrmm.net]
|
||||
|
||||
* Added trailing_slash option to url_for, so you can generate urls ending in a slash. Note that is currently not recommended unless you need it for special reasons since it breaks caching #937 [stian@grytoyr.net]
|
||||
|
||||
* Added expire_matched_fragments(regular_expression) to clear out a lot of fragment caches at once #927 [technoweenie@gmail.com]
|
||||
|
|
|
@ -148,11 +148,12 @@ module ActionView
|
|||
build_observer('Form.Observer', form_id, options)
|
||||
end
|
||||
|
||||
private
|
||||
# Escape carrier returns and single and double quotes for Javascript segments.
|
||||
def escape_javascript(javascript)
|
||||
(javascript || '').gsub('"', '\"')
|
||||
(javascript || '').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def options_for_ajax(options)
|
||||
js_options = build_callbacks(options)
|
||||
|
||||
|
|
9
actionpack/test/template/javascript_helper.rb
Normal file
9
actionpack/test/template/javascript_helper.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require File.dirname(__FILE__) + '/../abstract_unit'
|
||||
|
||||
class JavascriptHelperTest < Test::Unit::TestCase
|
||||
include ActionView::Helpers::JavascriptHelper
|
||||
|
||||
def test_escape_javascript
|
||||
assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue