Skip to content

Commit 8957ba5

Browse files
Fix sanitizer vendor config with 7.1 defaults
rails-html-santizer is a dependency of Action View and a transitive dependency of Action Text (via Action Pack), but may not be loaded until after railties sets configuration defaults. This change `require`s rails-html-sanitizer immediately before it's needed, and avoids the possibly-incorrect assumption that Rails::HTML::Sanitizer is already defined. Closes rails#51246 Co-authored-by: Rafael Mendonça França <[email protected]>
1 parent 2fa3294 commit 8957ba5

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)