Permalink
Browse files

String must be BINARY, if we use n option for regex (GH #3927).

  • Loading branch information...
1 parent cd7fbcb commit 8978bc9fc829ef935cf0393c759233db3edc4d33 @kennyj committed Dec 10, 2011
Showing with 8 additions and 1 deletion.
  1. +8 −1 activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -20,7 +20,14 @@ def html_escape(s)
if s.html_safe?
s
else
- s.gsub(/[&"><]/n) { |special| HTML_ESCAPE[special] }.html_safe
+ if force_binarize = ("".respond_to?(:force_encoding) && s.size != s.bytesize)
+ s = s.dup if s.frozen?
+ encoding = s.encoding
+ s.force_encoding("ASCII-8BIT")
+ end
+ s = s.gsub(/[&"><]/n) { |special| HTML_ESCAPE[special] }.html_safe
+ s.force_encoding(encoding) if force_binarize
+ s
end
end

0 comments on commit 8978bc9

Please sign in to comment.