railties: configure sanitizer vendor in 7.1 defaults more robustly #51267
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Background
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, meaning that the sanitizer vendor may remain
Rails::HTML4
and not be set toRails::HTML5
as we intend in Rails 7.1.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 #51246
If merged, this should be backported to 7-1-stable.
Additional information
Because the buggy behavior is dependent on the order in which libraries are loaded, it's difficult to add to the test suite.
I tested manually using the repro from #51246:
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]