Skip to content
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

Merged
merged 2 commits into from Jul 28, 2018

Conversation

hellofromtonya
Copy link
Contributor

@hellofromtonya hellofromtonya commented Jul 25, 2018

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.

Closes #1100.

See this comment where the issue was recreated.

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.
@hellofromtonya hellofromtonya added the Bug Something isn't working label Jul 25, 2018
@hellofromtonya hellofromtonya changed the title [WIP] Remove unrecognized elements and report. [WIP] Report removing unrecognized elements. Jul 25, 2018
Copy link
Member

@westonruter westonruter left a 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 ) {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.
@hellofromtonya
Copy link
Contributor Author

@westonruter I've added tests to ensure invalid elements with and without child nodes do get the right validation errors. Check out commit 65c9cde.

@westonruter westonruter changed the title [WIP] Report removing unrecognized elements. Report removing unrecognized elements. Jul 28, 2018
@westonruter westonruter merged commit 6be1d84 into develop Jul 28, 2018
@westonruter westonruter deleted the fix/silently-removing-unrecognized-elements branch July 28, 2018 00:05
@westonruter
Copy link
Member

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.

@westonruter westonruter added this to the v1.0 milestone Jul 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants