Skip to content

Commit 029d31c

Browse files
authored
Merge pull request rails#51267 from flavorjones/flavorjones-51246-rails-html-sanitizer
railties: configure sanitizer vendor in 7.1 defaults more robustly
2 parents 82e3252 + 8957ba5 commit 029d31c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

railties/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
* Fix sanitizer vendor configuration in 7.1 defaults.
2+
3+
In apps where rails-html-sanitizer was not eagerly loaded, the sanitizer default could end up
4+
being Rails::HTML4::Sanitizer when it should be set to Rails::HTML5::Sanitizer.
5+
6+
*Mike Dalessio*, *Rafael Mendonça França*
7+
18
* Set `action_mailer.default_url_options` values in `development` and `test`.
29

310
Prior to this commit, new Rails applications would raise `ActionView::Template::Error`

railties/lib/rails/application/configuration.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,14 @@ def load_defaults(target_version)
310310
active_support.raise_on_invalid_cache_expiration_time = true
311311
end
312312

313-
if defined?(Rails::HTML::Sanitizer) # nested ifs to avoid linter errors
314-
if respond_to?(:action_view)
315-
action_view.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor
316-
end
313+
if respond_to?(:action_view)
314+
require "rails-html-sanitizer"
315+
action_view.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor
316+
end
317317

318-
if respond_to?(:action_text)
319-
action_text.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor
320-
end
318+
if respond_to?(:action_text)
319+
require "rails-html-sanitizer"
320+
action_text.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor
321321
end
322322
when "7.2"
323323
load_defaults "7.1"

0 commit comments

Comments
 (0)