Skip to content

Instantly share code, notes, and snippets.

@MacksMind
Created March 16, 2013 23:51
Show Gist options
  • Save MacksMind/5178877 to your computer and use it in GitHub Desktop.
Save MacksMind/5178877 to your computer and use it in GitHub Desktop.
I'm in the middle of upgrading a Rails app from 2.3 to 3.2. There are many places where html strings are constructed and rendered. This monkey-patch has been a big help in finding all the places I need to use raw or html_safe.
module ActionView
class Template
def render_with_warn_on_escaped_html(*args,&block)
output = render_without_warn_on_escaped_html(*args,&block)
unless Rails.env.production? || args[0].request.instance_variables.include?(:@skip_escaped_html_check)
if output =~ /^.*<.*$/
warn "WARNING: Escaped HTML in #{ Rails.backtrace_cleaner.clean(caller).first }: #{Regexp.last_match}"
args[0].request.instance_variable_set(:@skip_escaped_html_check,true)
end
end
output
end
alias_method_chain :render, :warn_on_escaped_html
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment