Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #5380 from benmmurphy/escape_unicode_paragraph_sep…

…arator

ensure u2029 is escaped in escape_javascript helper
  • Loading branch information...
commit dea486d00ed8b9beec767324dfd15bec72d8a1ca 2 parents 2b05585 + c8168a7
@tenderlove tenderlove authored
View
4 actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -14,6 +14,8 @@ module JavaScriptHelper
}
JS_ESCAPE_MAP["\342\200\250".force_encoding('UTF-8').encode!] = '
'
+ JS_ESCAPE_MAP["\342\200\251".force_encoding('UTF-8').encode!] = '
'
+
# Escapes carriage returns and single and double quotes for JavaScript segments.
#
@@ -22,7 +24,7 @@ module JavaScriptHelper
# $('some_element').replaceWith('<%=j render 'some/element_template' %>');
def escape_javascript(javascript)
if javascript
- result = javascript.gsub(/(\\|<\/|\r\n|\342\200\250|[\n\r"'])/u) {|match| JS_ESCAPE_MAP[match] }
+ result = javascript.gsub(/(\\|<\/|\r\n|\342\200\250|\342\200\251|[\n\r"'])/u) {|match| JS_ESCAPE_MAP[match] }
javascript.html_safe? ? result.html_safe : result
else
''
View
2  actionpack/test/template/javascript_helper_test.rb
@@ -28,6 +28,8 @@ def test_escape_javascript
assert_equal %(backslash\\\\test), escape_javascript( %(backslash\\test) )
assert_equal %(dont <\\/close> tags), escape_javascript(%(dont </close> tags))
assert_equal %(unicode &#x2028; newline), escape_javascript(%(unicode \342\200\250 newline).force_encoding('UTF-8').encode!)
+ assert_equal %(unicode &#x2029; newline), escape_javascript(%(unicode \342\200\251 newline).force_encoding('UTF-8').encode!)
+
assert_equal %(dont <\\/close> tags), j(%(dont </close> tags))
end
Please sign in to comment.
Something went wrong with that request. Please try again.