Skip to content

Commit

Permalink
fix: edge case lazyload replacement when noscript images are present
Browse files Browse the repository at this point in the history
  • Loading branch information
selul committed Dec 3, 2019
1 parent 8e73668 commit c788c3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion inc/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public static function parse_images_from_html( $content ) {
$header_end = $header_start + strlen( $matches[0][0] );
}

if ( preg_match_all( '/(?:<a[^>]+?href=["|\'](?P<link_url>[^\s]+?)["|\'][^>]*?>\s*)?(?P<img_tag>(?:<noscript\s*>\s*)?<img[^>]*?\s+?(?:' . implode( '|', array_merge( [ 'src' ], Optml_Tag_Replacer::possible_src_attributes() ) ) . ')=\\\\?["|\'](?P<img_url>[^\s]+?)["|\'].*?>(?:<\/noscript\s*>)?){1}(?:\s*<\/a>)?/ism', $content, $images, PREG_OFFSET_CAPTURE ) ) {
if ( preg_match_all( '/(?:<a[^>]+?href=["|\'](?P<link_url>[^\s]+?)["|\'][^>]*?>\s*)?(?P<img_tag>(?:<noscript\s*>\s*)?<img[^>]*?\s+?(?:' . implode( '|', array_merge( [ 'src' ], Optml_Tag_Replacer::possible_src_attributes() ) ) . ')=\\\\?["|\'](?P<img_url>[^\s]+?)["|\'].*?>(?:\s*<\/noscript\s*>)?){1}(?:\s*<\/a>)?/ism', $content, $images, PREG_OFFSET_CAPTURE ) ) {

foreach ( $images as $key => $unused ) {
// Simplify the output as much as possible, mostly for confirming test results.
Expand Down
6 changes: 5 additions & 1 deletion tests/test-lazyload.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ public function test_check_with_multiple_images_in_no_script() {
}

public function test_check_lazy_load_after_no_script() {
$content = '<noscript><img height="1" width="1" style="display:none" alt="fbpx" src="https://www.facebook.com/tr?id=dasda&ev=PageView&noscript=1" /></noscript>
$content = '
<noscript>
<img height="1" width="1" style="display:none" alt="fbpx"
src="https://www.facebook.com/tr?id=472300923567306&ev=PageView&noscript=1" />
</noscript>
<a href="/project/test-one"><span class="et_pb_image_wrap"><img src="http://example.org/wp-content/uploads/2018/11/gradient.png" alt="" /></span></a>
<a href="/project/test-two"><span class="et_pb_image_wrap"><img src="http://example.org/wp-content/uploads/2018/11/gradient.png" alt="" /></span></a>
<a href="/project/test-three"><span class="et_pb_image_wrap"><img src="http://example.org/wp-content/uploads/2018/11/gradient.png" alt="" /></span></a>
Expand Down

0 comments on commit c788c3f

Please sign in to comment.