From feababcf30d797f7c0798ff13acf210c7e8374b0 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 20 Mar 2020 21:56:28 -0700 Subject: [PATCH] Prevent case where validation error can be raised on already-removed node This prevents a validation error from having no source stack --- .../sanitizers/class-amp-tag-and-attribute-sanitizer.php | 7 +++---- tests/php/test-tag-and-attribute-sanitizer.php | 5 ----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php index ba266d05722..fa3b8eb416f 100644 --- a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php +++ b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php @@ -535,10 +535,9 @@ static function ( $validation_error ) { } else { // Otherwise, we have a rare condition where multiple tag specs fail for different reasons. foreach ( $validation_errors as $validation_error ) { - $this->remove_invalid_child( - $node, - $validation_error - ); + if ( true === $this->remove_invalid_child( $node, $validation_error ) ) { + break; // Once removed, ignore remaining errors. + } } } } diff --git a/tests/php/test-tag-and-attribute-sanitizer.php b/tests/php/test-tag-and-attribute-sanitizer.php index 959d7ac1591..78c840365a4 100644 --- a/tests/php/test-tag-and-attribute-sanitizer.php +++ b/tests/php/test-tag-and-attribute-sanitizer.php @@ -96,11 +96,6 @@ public function get_body_data() { 'spec_name' => 'noscript enclosure for boilerplate', 'required_parent_name' => 'head', ], - [ - 'code' => AMP_Tag_And_Attribute_Sanitizer::DISALLOWED_TAG_ANCESTOR, - 'disallowed_ancestor' => 'noscript', - 'spec_name' => 'noscript', - ], ], ],