Skip to content

Instantly share code, notes, and snippets.

@mccabe615
Created March 26, 2014 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mccabe615/9785085 to your computer and use it in GitHub Desktop.
Save mccabe615/9785085 to your computer and use it in GitHub Desktop.
Patched Bootstrap flash helper to prevent XSS.
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