From 1becc63e4c946b4fc3a15fa58bf940e4b6434787 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 8 Feb 2018 10:30:06 -0800 Subject: [PATCH] Prevent removing elements that have freeform attributes --- .../sanitizers/class-amp-tag-and-attribute-sanitizer.php | 6 ++++++ tests/test-tag-and-attribute-sanitizer.php | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php index 2794b6ba432..32d243a41f8 100644 --- a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php +++ b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php @@ -530,6 +530,12 @@ private function validate_attr_spec_list_for_node( $node, $attr_spec_list ) { */ foreach ( $attr_spec_list as $attr_name => $attr_spec_rule ) { + // If attr spec rule is empty, then it allows anything. + if ( empty( $attr_spec_rule ) && $node->hasAttribute( $attr_name ) ) { + $score++; + continue; + } + // If a mandatory attribute is required, and attribute exists, pass. if ( isset( $attr_spec_rule[ AMP_Rule_Spec::MANDATORY ] ) ) { $result = $this->check_attr_spec_rule_mandatory( $node, $attr_name, $attr_spec_rule ); diff --git a/tests/test-tag-and-attribute-sanitizer.php b/tests/test-tag-and-attribute-sanitizer.php index 824b8164d2b..5bb515f41d9 100644 --- a/tests/test-tag-and-attribute-sanitizer.php +++ b/tests/test-tag-and-attribute-sanitizer.php @@ -755,7 +755,7 @@ public function get_html_data() { ), 'bad_meta_ua_compatible' => array( '', - '', + '', // Note the http-equiv is removed because the content violates its attribute spec. ), 'bad_meta_charset' => array( 'Mojibake?', @@ -773,6 +773,10 @@ public function get_html_data() { '', null, // No change. ), + 'meta_og_property' => array( + '', + null, // No change. + ), ); // Also include the body tests.