-
-
Save rgrove/282168 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
# remove content of script tags using Sanitize | |
require 'sanitize' | |
html = '<p>Do not<script>fail();</script> kill the <a href="/cats/42">cat</a>.</p>' | |
Sanitize.clean(html, Sanitize::Config::BASIC.merge( | |
:transformers => lambda { |env| | |
node = env[:node] | |
if node.name.downcase == 'script' | |
node.unlink | |
return {} | |
end | |
} | |
)) | |
# => "<p>Do not kill the <a href=\"/cat/42\" rel=\"nofollow\">cat</a>.</p>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment