yireo / Yireo_Webp2

Magento 2 module to add WebP support to Magento 2
Open Software License 3.0
194 stars 54 forks source link

"{image_path}" is not matched with a local file #119

Closed sharjilk closed 9 months ago

sharjilk commented 2 years ago

On product listing page, image tag still present but on product detail page I am having below error.

1 exception(s): Exception #0 (Magento\Framework\View\Asset\File\NotFoundException): URL "https://local.test/media/catalog/product/cache/ff32d94df7540053a6b1040b58ae5eec/l/e/lebs15294.jpg" is not matched with a local file

Browser :- Chrome latest Magento version :- 2.4.1 PHP version:- 7.4 Yireo WebP2 composer version:- 0.12.0 Yireo NextGenImages composer version:- 0.3.0

Settings below

1 2

Here's below output of bin/magento dev:di:info "\Magento\Framework\View\LayoutInterface"

3
thijsdewitt commented 2 years ago

I created the following patch to fix this issue.

@package yireo/magento2-next-gen-images

Index: /Util/UrlConvertor.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Util/UrlConvertor.php b/Util/UrlConvertor.php
--- a/Util/UrlConvertor.php
+++ b/Util/UrlConvertor.php (date 1652711174555)
@@ -101,6 +101,7 @@
      */
     public function getFilenameFromUrl(string $url): string
     {
+        $url = html_entity_decode($url);
         $url = preg_replace('/\/static\/version([0-9]+\/)/', '/static/', $url);

         if ($this->isLocal($url) === false) {
jissereitsma commented 2 years ago

@thijsdewitt Thanks for jumping in. Note though that it is small little changes like these that are best to pick up as Pull Requests in an open source project like this. The fix will be included in the next release: https://github.com/yireo/Yireo_NextGenImages/commit/8040da540a749251d764418a6c6dfbc85270eb0a

jissereitsma commented 2 years ago

@sharjilk If this fixes your issue, could you close the ticket?

guittavares commented 1 year ago

Hello everything is fine? I'm going through a similar situation.

PHP 7.3.33 Magento 2.3.5-p2 Yireo NextGenImages Module version 0.4.0 Yireo WebP2 Module version 0.12.5

When running the command bin/magento dev:di:info "\Magento\Framework\View\LayoutInterface" the error output is the same, however in the LOG appears the pub folder duplicated in the URL

[2023-06-28 15:07:27] main.NOTICE: Source cached image does not exist: /home/mrae/public_html/pub/pub/media/logo/default/mrae-logotipo.png: array ( 'path' => '/home/mrae/public_html/pub/pub/media/logo/default/mrae-logotipo.png', ) [] [] [2023-06-28 15:07:27] main.NOTICE: Source cached image does not exist: /home/mrae/public_html/pub/pub/media/logo/websites/1/mrae-logotipo.png: array ( 'path' => '/home/mrae/public_html/pub/pub/media/logo/websites/1/mrae-logotipo.png', ) [] []

jissereitsma commented 1 year ago

I still don't know what the useful is of the bin/magento dev:di:info command in this case. But anyway, the notices are pointing to something off. What is the output of the command bin/magento next-gen-images:test-uri URL where URL is replaced with the actual URL to the image?

What are the settings that you configured for both the NextGenImages module and the WebP2 module?

guittavares commented 1 year ago

Captura de Tela 2023-06-28 às 15 07 27

jissereitsma commented 1 year ago

Thanks. This URL actually shows that the pub/ is visible in your URLs, meaning that the root of your application is exposed for scanning if people are smart enough. Are you sure that you want to keep running this configuration, while actually everyone would be advising to configure the webserver to use the folder pub/ as your Document Root, and not the application folder?

I never tested for this, because of the security issues involved here. I'm still going to pursue a fix, but I wanted to point out already that not using the pub/ folder as a Document Root suggests another fix with more priority.

guittavares commented 1 year ago

Thanks for the feedback. I work with Cpanel and Apache 2.4 and I was not able to configure the webroot, so I had installed it in the root folder. After a lot of research, I found out how to make the adaptation and now the module is working perfectly. Thank you very much for the help

jissereitsma commented 9 months ago

The new version 0.5.0 NextGenImages should fix this. Could you upgrade? And also upgrade the WebP version to the latest version? I'm closing this issue as of yet, but if things are still not working, feel free to reopen this issue.