Skip to content

Commit

Permalink
fix issues when the dam image urls tags don't have width/height by us…
Browse files Browse the repository at this point in the history
…ing the width/height arguments when present
  • Loading branch information
selul committed Jan 10, 2025
1 parent 65a87ae commit 139c42e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions inc/app_replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,15 @@ protected function parse_dimensions_from_filename( $src ) {
if ( $width && $height ) {
return [ $width, $height, $crop ];
}
} else {
$optimized_args = $this->parse_dimension_from_optimized_url( $src );
if ( $optimized_args[0] !== 'auto' && $optimized_args[1] !== 'auto' ) {
return [
$optimized_args[0] !== 'auto' ? (int) $optimized_args[0] : false,

Check failure on line 619 in inc/app_replacer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.0

Else branch is unreachable because ternary operator condition is always true.
$optimized_args[1] !== 'auto' ? (int) $optimized_args[1] : false,

Check failure on line 620 in inc/app_replacer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.0

Else branch is unreachable because ternary operator condition is always true.
false,
];
}
}

return [ false, false, false ];
Expand Down
1 change: 1 addition & 0 deletions inc/tag_replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
final class Optml_Tag_Replacer extends Optml_App_Replacer {
use Optml_Normalizer;
use Optml_Validator;
use Optml_Dam_Offload_Utils;

/**
* Cached object instance.
Expand Down
10 changes: 10 additions & 0 deletions tests/test-lazyload.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Test_Lazyload extends WP_UnitTestCase {
<img src="http://example.org/wp-content/optimole-wp/assets/img/logo5.gif">
';
const DAM_IMG_TAG = '<img width="100" height="200" src="https://cloudUrlTest.test/dam:1/w:auto/h:auto/q:auto/id:b1b12ee03bf3945d9d9bb963ce79cd4f/https://test-site.test/9.jpg">';
const DAM_IMG_TAG_NO_WIDTH = '<img src="https://cloudUrlTest.test/w:200/h:300/process:20202/q:auto/id:b1b12ee03bf3945d9d9bb963ce79cd4f/https://test-site.test/9.jpg">';
public function setUp() : void {
parent::setUp();
$settings = new Optml_Settings();
Expand Down Expand Up @@ -575,4 +576,13 @@ public function test_dam_lazyloading() {

$this->assertStringContainsString( 'data-opt-src="https://cloudUrlTest.test/w:100/h:200/rt:fill/g:ce/ig:avif/q:mauto/id:b1b12ee03bf3945d9d9bb963ce79cd4f/https://test-site.test/9.jpg"', $replaced_content );
}
public function test_dam_lazyloading_no_wh_attributes() {
add_filter('optml_lazyload_images_skip','__return_zero');
Optml_Manager::instance()->lazyload_replacer->settings->update('lazyload_placeholder','enabled');
Optml_Manager::instance()->lazyload_replacer->init();
$replaced_content = Optml_Manager::instance()->process_images_from_content( self::DAM_IMG_TAG_NO_WIDTH );
$svg = Optml_Manager::instance()->lazyload_replacer->get_svg_for( 200, 300, 'http://example.org/testimage.png' );
$this->assertStringContainsString( $svg, $replaced_content );
remove_filter('optml_lazyload_images_skip','__return_zero');
}
}

0 comments on commit 139c42e

Please sign in to comment.