New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report removing unrecognized elements. #1287
Report removing unrecognized elements. #1287
Conversation
Closes #1100. Fixes the problem of silently removing unrecognized elements. Uses the same code pattern and methodology as `remove_invalid_child`: - Prevent double-reporting nodes that are rejected. - Check through should_sanitize_validation_error(). - Replace if true. - Else, store in the `should_not_replace_nodes` property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good so far, other than the condition of when there is no parent node and no child nodes. This should also get unit tests to check for the new scenarios for when validation errors can be reported for the various removals of invalid elements.
* | ||
* @param DOMNode $node Node. | ||
*/ | ||
private function replace_node_with_children( $node ) { | ||
|
||
// If node has no children or no parent, just remove the node. | ||
if ( ! $node->hasChildNodes() || ! $node->parentNode ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not there be a $this->should_sanitize_validation_error( array(), compact( 'node' ) )
call in here as well? Otherwise the removal won't be reported as a validation error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@westonruter the if
code block flows through to remove_node()
where it’s handled. I did confirm it there. When I write the error unit tests, I’ll validate that too to ensure we have reporting for both paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you're right. \AMP_Tag_And_Attribute_Sanitizer::remove_node()
will call \AMP_Base_Sanitizer::remove_invalid_child()
which reports the validation error. 👍
These tests check that invalid nodes do pop validation errors.
@westonruter I've added tests to ensure invalid elements with and without child nodes do get the right validation errors. Check out commit 65c9cde. |
Good work! Great to have this as part of 1.0. This will help a lot when someone tries to use an AMP component that is misspelled or tries to use a new AMP component that is not yet recognized due to the spec not being updated. |
Fixes the problem of silently removing unrecognized elements. Uses the same code pattern and methodology as
remove_invalid_child
:should_not_replace_nodes
property.Closes #1100.
See this comment where the issue was recreated.