Last active
December 18, 2015 04:58
-
-
Save kaspth/5728856 to your computer and use it in GitHub Desktop.
A new API proposal for custom HTML scrubbing.
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
# By switching out the html-scanner lib with Loofah, we can make use of the custom HTML scrubbers within Loofah to get more control over what gets sanitized. | |
# This could be useful in apps where users submit text content. | |
# Say Twitter in an alternate universe allows users to format their tweets using some HTML tags. They then need a way to specify what tags are black- and/or whitelisted. | |
# This is an example of how it could work in a model. | |
class Comment < ActiveRecord::Base | |
# block based | |
# block takes a node | |
scrubs :body do |node| | |
node.remove if node.name == "script" | |
end | |
# method based | |
# method is last argument and has a node parameter | |
scrubs :name, :body, :remove_style_blocks | |
# list based via a kind option | |
# options are based on the available scrubbers in Loofah | |
scrubs :name, kind: :whitelist | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment