diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2011-08-23 14:55:31 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2011-08-23 14:56:04 +0100 |
commit | 13400ac289344dae002c77a3c2b820268f08745e (patch) | |
tree | 837ec5a22cfa29c2c8d59c8995bef0fd408e0e0a /actionpack/lib | |
parent | f7f9003cd54a697fbacebb01675dc6a7467fbf88 (diff) | |
download | rails-13400ac289344dae002c77a3c2b820268f08745e.tar.gz rails-13400ac289344dae002c77a3c2b820268f08745e.tar.bz2 rails-13400ac289344dae002c77a3c2b820268f08745e.zip |
Ensure regexp and hash key are UTF-8
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/javascript_helper.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index f1b071caf7..474ea53f91 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -1,4 +1,5 @@ require 'action_view/helpers/tag_helper' +require 'active_support/core_ext/string/encoding' module ActionView module Helpers @@ -10,8 +11,14 @@ module ActionView "\n" => '\n', "\r" => '\n', '"' => '\\"', - "'" => "\\'", - "\342\200\250" => '
' } + "'" => "\\'" + } + + if "ruby".encoding_aware? + JS_ESCAPE_MAP["\342\200\250".force_encoding('UTF-8').encode!] = '
' + else + JS_ESCAPE_MAP["\342\200\250"] = '
' + end # Escape carrier returns and single and double quotes for JavaScript segments. # Also available through the alias j(). This is particularly helpful in JavaScript responses, like: @@ -19,7 +26,7 @@ module ActionView # $('some_element').replaceWith('<%=j render 'some/element_template' %>'); def escape_javascript(javascript) if javascript - result = javascript.gsub(/(\\|<\/|\r\n|\342\200\250|[\n\r"'])/) {|match| JS_ESCAPE_MAP[match] } + result = javascript.gsub(/(\\|<\/|\r\n|\342\200\250|[\n\r"'])/u) {|match| JS_ESCAPE_MAP[match] } javascript.html_safe? ? result.html_safe : result else '' |