Skip to content

Commit

Permalink
Sanotize img tags when src attribute contains only spaces. Fixes issue
Browse files Browse the repository at this point in the history
  • Loading branch information
amedina authored and westonruter committed Apr 3, 2018
1 parent 67a8a69 commit a75f27d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion includes/sanitizers/class-amp-img-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function sanitize() {
continue;
}

if ( ! $node->hasAttribute( 'src' ) || '' === $node->getAttribute( 'src' ) ) {
if ( ! $node->hasAttribute( 'src' ) || '' === trim( $node->getAttribute( 'src' ) ) ) {
$this->remove_invalid_child( $node );
continue;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/test-amp-img-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public function get_data() {
'<p></p>',
),

'image_with_spaces_only_src' => array(
'<p><img src=" " width="300" height="300" /></p>',
'<p></p>',
),

'image_with_empty_width_and_height' => array(
'<p><img src="http://placehold.it/300x300" width="" height="" /></p>',
'<p><amp-img src="http://placehold.it/300x300" width="600" height="400" class="amp-wp-unknown-size amp-wp-enforced-sizes" sizes="(min-width: 600px) 600px, 100vw"></amp-img></p>',
Expand Down

0 comments on commit a75f27d

Please sign in to comment.