Created
March 26, 2014 14:50
-
-
Save mccabe615/9785085 to your computer and use it in GitHub Desktop.
Patched Bootstrap flash helper to prevent XSS.
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 BootstrapFlashHelperPatched | |
ALERT_TYPES = [:error, :info, :success, :warning] unless const_defined?(:ALERT_TYPES) | |
def bootstrap_flash_patched | |
flash_messages = [] | |
flash.each do |type, message| | |
# Skip empty messages, e.g. for devise messages set to nothing in a locale file. | |
next if message.blank? | |
type = type.to_sym | |
type = :success if type == :notice | |
type = :error if type == :alert | |
next unless ALERT_TYPES.include?(type) | |
Array(message).each do |msg| | |
text = content_tag(:div, | |
content_tag(:button, raw("×"), :class => "close", "data-dismiss" => "alert") + | |
msg, :class => "alert fade in alert-#{type}") | |
flash_messages << text if msg | |
end | |
end | |
flash_messages.join("\n").html_safe | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment