From 65f1c0c8229c819aed6bf105a27d8b52d000a43e Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 28 Mar 2019 22:00:16 -0700 Subject: [PATCH] Remove obsolete add_auto_width_to_figure from #1086 --- .../sanitizers/class-amp-img-sanitizer.php | 35 ------------------- tests/test-amp-img-sanitizer.php | 8 ++--- 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/includes/sanitizers/class-amp-img-sanitizer.php b/includes/sanitizers/class-amp-img-sanitizer.php index b562a5bf908..c4ce753e768 100644 --- a/includes/sanitizers/class-amp-img-sanitizer.php +++ b/includes/sanitizers/class-amp-img-sanitizer.php @@ -275,8 +275,6 @@ private function adjust_and_replace_node( $node ) { $noscript = $this->dom->createElement( 'noscript' ); $noscript->appendChild( $node ); $img_node->appendChild( $noscript ); - - $this->add_auto_width_to_figure( $img_node ); } /** @@ -320,37 +318,4 @@ private function is_gif_url( $url ) { $path = wp_parse_url( $url, PHP_URL_PATH ); return substr( $path, -strlen( $ext ) ) === $ext; } - - /** - * Add an inline style to set the `
` element's width to `auto` instead of `fit-content`. - * - * @since 1.0 - * @see https://github.com/ampproject/amp-wp/issues/1086 - * - * @param DOMElement $node The DOMNode to adjust and replace. - */ - protected function add_auto_width_to_figure( $node ) { - $figure = $node->parentNode; - if ( ! ( $figure instanceof DOMElement ) || 'figure' !== $figure->tagName ) { - return; - } - - $class = $figure->getAttribute( 'class' ); - // Target only the
with a 'wp-block-image' class attribute. - if ( false === strpos( $class, 'wp-block-image' ) ) { - return; - } - - // Target only
without a 'is-resized' class attribute. - if ( false !== strpos( $class, 'is-resized' ) ) { - return; - } - - $new_style = 'width: auto;'; - if ( $figure->hasAttribute( 'style' ) ) { - $figure->setAttribute( 'style', $new_style . $figure->getAttribute( 'style' ) ); - } else { - $figure->setAttribute( 'style', $new_style ); - } - } } diff --git a/tests/test-amp-img-sanitizer.php b/tests/test-amp-img-sanitizer.php index e77274c1457..d8d103a4b82 100644 --- a/tests/test-amp-img-sanitizer.php +++ b/tests/test-amp-img-sanitizer.php @@ -187,22 +187,22 @@ public function get_data() { 'wide_image' => array( '
Image Alignment 580x300
', - '
', + '
', ), 'wide_image_center_aligned' => array( '
Image Alignment 580x300
', - '
', + '
', ), 'wide_image_left_aligned_custom_style' => array( '
Image Alignment 580x300
', - '
', + '
', ), 'wide_image_right_aligned' => array( '
Image Alignment 580x300
', - '
', + '
', ), 'wide_image_is_resized' => array(