Browse files

Fixed escaping of backslashes in JavaScriptHelper#escape_javascript (…

…closes #6302) [sven@c3d2.de]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5242 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2e766b1 commit 4b3e964a1a9d9b5c4a7925ccb8a0090f869fdca4 @dhh dhh committed Oct 9, 2006
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed escaping of backslashes in JavaScriptHelper#escape_javascript #6302 [sven@c3d2.de]
+
* Fixed that some 500 rescues would cause 500's themselves because the response had not yet been generated #6329 [cmselmer]
* respond_to :html doesn't assume .rhtml. #6281 [Hampton Catlin]
View
2 actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -149,7 +149,7 @@ def define_javascript_functions
# Escape carrier returns and single and double quotes for JavaScript segments.
def escape_javascript(javascript)
- (javascript || '').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
+ (javascript || '').gsub('\\','\0\0').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
end
# Returns a JavaScript tag with the +content+ inside. Example:
View
1 actionpack/test/template/javascript_helper_test.rb
@@ -19,6 +19,7 @@ def test_define_javascript_functions
def test_escape_javascript
assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
+ assert_equal %(backslash\\\\test), escape_javascript( %(backslash\\test) )
end
def test_link_to_function

0 comments on commit 4b3e964

Please sign in to comment.