Update Action Text to use HTML5 when available #48522
Merged
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
Update Action Text to use the HTML5 sanitizer when available, and to parse markup using Nokogiri::HTML5 when available. Previously, Action Text used Nokogiri's HTML4 parsers for these operations.
Detail
This pull request updates the default value for
ActionText::ContentHelper.sanitizer
fromRails::Html::Sanitizer.safe_list_sanitizer.new
toRails::Html::Sanitizer.best_supported_vendor.safe_list_sanitizer.new
. The method.best_supported_vendor
is available in rails-html-sanitizer v1.6.0 and later, which 500ccaa made the minimum for Action View.This pull request also adds two new methods that return the "best supported" HTML document and document fragment classes:
ActionText.html_document_class
andActionText.html_document_fragment_class
. These methods are used internally where code previously referencedNokogiri::HTML
directly.The change from
#clone
to#dup
is necessary to work around an issue in Nokogiri where#clone
is not defined properly for HTML5 fragment and the fragment does not have a parent Document.#dup
behaves the way we expect, so this should be fine.Additional information
This is part of ongoing work to update Rails to use HTML5.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]