yireo / Yireo_NextGenImages

44 stars 26 forks source link

Img detect not work in some case #23

Closed mibesoft closed 2 weeks ago

mibesoft commented 2 years ago

I found some case image detect in file Yireo\NextGenImages\Image\HtmlReplacer function replaceImagesInHtml not working

<p> <img style="float: right;" title="title" src="https://example.com/image.png" alt="Titme" width="320" height="219" /> Text </p>

jissereitsma commented 2 years ago

Thanks for your suggestion. There is a refactoring underway, so that this will need to be applied in a different way. Once that's done, I'll get back to this question.

RetroProgrammist commented 1 year ago

Hello, in the current version (0.3.12) While working I found out that getPictureHtmlFromImage method returns empty string if img has only data-src attribute.

        $imageUrl = $image->getAttribute('src');      
        if (!$this->isAllowedByImageUrl($imageUrl)) {
            return '';
        }

        $images = $this->imageCollector->collect($imageUrl);
        if (!count($images) > 0) {
            return '';
        }

Because it does not pass the check above I corrected it as follows:

        $imageUrl = $image->getAttribute('src')?:$image->getAttribute('data-src');
        if (!$this->isAllowedByImageUrl($imageUrl)) {
            return '';
        }
jissereitsma commented 1 year ago

@mibesoft Sorry for the long delay. I have tested for this, but am unable to reproduce anything. You say that it is not working. But what is the expected output? (The input is what you already posted.)

@RetroProgrammist Good catch. Indeed I was able to duplicate this unwanted error. Next, I've added an integration test to confirm the bug, apply the fix you mentioned and see the test succceed. The fix will be available in the next release (to be released today).

I'll keep this issue open for further notice.

jissereitsma commented 2 weeks ago

I'm closing this due to inactivity. Let me know if this is not yet fixed already.