Skip to content

Commit

Permalink
use railtie to set default sanitizer
Browse files Browse the repository at this point in the history
* add rails as a test dependency to fix tests
  • Loading branch information
tongueroo committed Oct 15, 2023
1 parent 19fd6cd commit 891625c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Expand Up @@ -18,3 +18,7 @@ end
# specify gem versions for old rubies
gem "nokogiri", RUBY_VERSION < "2.1" ? "~> 1.6.0" : ">= 1.7"
gem "activesupport", RUBY_VERSION < "2.2.2" ? "~> 4.2.0" : ">= 5"

group :test do
gem "rails", "~> 7.1.1"
end
2 changes: 2 additions & 0 deletions lib/rails-html-sanitizer.rb
Expand Up @@ -59,3 +59,5 @@ def deprecate_option(name)
end
end
end

require_relative "railtie"
18 changes: 18 additions & 0 deletions lib/railtie.rb
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require "rails"
require "rails/html/sanitizer"

module Rails
module HTML
class Sanitizer
class Railtie < Rails::Railtie # :nodoc:
initializer "rails_html_sanitizer.sanitizer_vendor" do |app|
ActiveSupport.on_load(:action_view) do
ActionView::Helpers::SanitizeHelper.sanitizer_vendor = Rails::HTML4::Sanitizer
end
end
end
end
end
end

0 comments on commit 891625c

Please sign in to comment.