Fix handling of child_tag_name_oneof constraint in tag spec#2926
Merged
westonruter merged 1 commit intodevelopfrom Aug 1, 2019
Merged
Fix handling of child_tag_name_oneof constraint in tag spec#2926westonruter merged 1 commit intodevelopfrom
westonruter merged 1 commit intodevelopfrom
Conversation
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In reviewing the Newspack theme (https://github.com/Automattic/newspack-theme/pull/120/files#r309371902), I was seeing something very strange in regards to markup like:
The AMP plugin was marking it as invalid as if it was matching the
amp-sidebar > navtag spec, specifically due to thechild_tagsconstraint:But this made no sense because this tag spec should not be considered at all because the
navdoes not have thetoolbarortoolbar-targetattributes which are also part of that tag spec:The reason turns out to be that the DOM was being mutated while checking for candidate tag specs to validate against a given node.
When beginning to
process_node, we have to gather up a list of candidate tag specs to validate the node against:amp-wp/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php
Lines 402 to 415 in 1a3646e
This loop is only checking for candidate tag specs; it should not be doing any sanitization. Nevertheless, the
validate_tag_spec_for_node()method call there was doing this in its last line:amp-wp/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php
Line 713 in 1a3646e
The
check_valid_children()method call here was erroneously mutating the document, while checking to see if thenavis a match for that tag spec. The actual tag spec that should only be considered here is thenavspec which has no constraints on the children:This is a bug that was introduced in v1.1 via #1860.
👉 A side-effect of the change here is the sanitization of AMP components with invalid children will be more draconian. For example, if an
amp-storyhas an invalid child element, then the entireamp-storyelement will be removed, as opposed to the invalid child alone being removed. Nevertheless, since only AMP components have such validation constraints for children, it should not so common for this to occur in WordPress sites that are just outputting normal HTML. It only will become an issue when starting to use AMP components, and this makes #1420 much more important as it will be needed to explain why the element was removed.