Skip to content

Instantly share code, notes, and snippets.

@jamescway
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save jamescway/9406983 to your computer and use it in GitHub Desktop.

Select an option

Save jamescway/9406983 to your computer and use it in GitHub Desktop.
rails 2 utf-8
if Rails::VERSION::MAJOR == 2
require "active_support/core_ext/string/output_safety"
class ERB
module Util
# see https://github.com/rails/rails/issues/7430
def html_escape(s)
s = s.to_s
if s.html_safe?
s
else
s.gsub(/[&"'><]/, HTML_ESCAPE).html_safe
end
end
alias h html_escape
singleton_class.send(:remove_method, :html_escape)
module_function :html_escape, :h
end
end
else
puts "You can delete this file+test now #{__FILE__}"
end
@jamescway
Copy link
Author

filters out weird utf-8 error
/usr/local/rvm/gems/ruby-1.9.3-p0/gems/activesupport-2.3.17/lib/active_support/core_ext/string/output_safety.rb:22: warning: regexp match /.../n against to UTF-8 string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment