Consider element attributes when determining if a parent element is empty and can be removed#2051
Merged
westonruter merged 2 commits intodevelopfrom Apr 2, 2019
Merged
Conversation
amedina
reviewed
Apr 2, 2019
| } | ||
| while ( $parent && ! $parent->hasChildNodes() && $this->root_element !== $parent ) { | ||
|
|
||
| // @todo Does this parent removal even make sense anymore? |
Member
There was a problem hiding this comment.
Are you referring to alternatively not removing empty parent nodes?
Member
Author
There was a problem hiding this comment.
Yes, that's right. We should evaluate why this was added in the first place, and consider discontinuing the practice.
I believe it may have been due to having input like this:
<p><script>evil</script></p>Normally this would sanitized as:
<p></p>That results in what appears to be a blank area in the page. So apparently it helps in that case. But we should consider being more limited in what we consider to be suitable for removal. For example, perhaps this only makes sense for p elements.
amedina
reviewed
Apr 2, 2019
Member
amedina
left a comment
There was a problem hiding this comment.
LGTM. Removing the empty parent nodes seems necessary (regarding the comment).
5 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.
We discovered an issue when a site is served via HTTP instead of HTTPS. An
amp-imgallows for its image to use thehttpprotocol, so this is valid AMP:With #1861 there was introduced
noscript > imgfallbacks for serving when a user with JS disabled accesses a (canonical) AMP page. This results in markup like:It turns out that this actually is invalid AMP:
The
srcandsrcsetattributes are flagged as errors because—perhaps unintentionally—thenoscript > imgelement does not allow thehttpprotocol.The resulting behavior is the tag-and-attribute sanitizer proceeds to remove the
img. Then theAMP_Tag_And_Attribute_Sanitizer::remove_node()has awhileloop to walk up the DOM tree to examine each parent, and for each empty parent, they are removed. This is a problem becausenoscriptis an empty element is removed andamp-imgis also then an empty element and is removed. The problem is that “emptiness” is not taking into account the attributes of the parent elements. So this fixes that. Nevertheless, we should also evaluate in the future if empty parents really should be removed in the first place.An issue also needs to be opened against the AMPHTML validator to allow
httpprotocol fornoscript > imgelements.Also fixes tests which apparently break when testing on WordPress 4.9 and the latest Gutenberg by explicitly installing an old version of Gutenberg that works with 4.9.