Created
July 29, 2008 21:20
-
-
Save anotherjesse/3178 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
class Base | |
# FIXME - WE SHOULD NOT PUT THESE INSIDE AR:B | |
include ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper, WhiteListHelper | |
def self.sanitize(attr_name, options = {}) | |
define_method "#{attr_name}=" do |val| | |
write_attribute attr_name, val | |
html = '' | |
val.strip! if val.respond_to?(:strip!) | |
unless val.blank? | |
# Turn URLs and e-mails into links | |
html = auto_link(val) | |
# Turn newlines into <p> or <br /> | |
html = unsimple_format(html) | |
# Escape entities, remove bad tags and attributes/values | |
html = white_list(html, {}) do |node, bad| | |
if white_listed_bad_tags.include?(bad) then | |
nil | |
else | |
node.to_s.gsub(/&(?!#?\w+;)/, '&').gsub(/</, '<') | |
end | |
end | |
html = wordwrap(html) | |
end | |
write_attribute "#{attr_name}_html", html | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment