Introduce transform_important_qualifiers
arg to AMP_Style_Sanitizer
#6589
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.
Summary
This is cherry-picked from #6577 and is essentially amending #6528. When custom scripts are on the page, it's important that inline
style
rules be left as-is without being transformed into style rules. Take comment replying for example. The cancel reply link from core getsstyle="display:none"
. The style sanitizer by default converts that into a style rule:root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-cb45893 {display: none}
and thestyle
attribute will be replaced withdata-amp-original-style="display:none"
andclass="amp-wp-cb45893"
. Whencomment-reply.js
then tries to show the link by removing the thedisplay
property, nothing happens because the style has been applied with a style rule instead.This PR adds a
transform_important_qualifiers
arg toAMP_Style_Sanitizer
which will preventstyle
attributes from being converted into style rules, while also preventing the transformation of any!important
qualifiers into style rules with high specificity. The latter transformation is actually the reason for the former, since specificity can only be maintained if all styles are moved to style rules.This argument is
false
by default so that the valid-AMP behavior of preventing!important
from appearing in the page will be preserved.This sanitizer arg will be enabled as part of the above PR or #6546.
Checklist