FriendsOfShopware / FroshPlatformHtmlMinify

This plugin allows you to minify your HTML output.
MIT License
10 stars 3 forks source link

Division by zero when payload is empty #7

Closed edvvogel closed 3 years ago

edvvogel commented 3 years ago

PHP Version

8.0

Shopware Version

6.4.3.1

Actual behaviour

When loading empty content via ajax (effectively empty twig file), a DivisionByZeroError is thrown in custom/plugins/FroshPlatformHtmlMinify/src/Listener/ResponseListener.php (line 153)

private function assignCompressionHeader(Response $response, string $content, int $lengthInitialContent, float $startTime): void { $lengthContent = mb_strlen($content, 'utf8'); **$savedData = round(100 - 100 / ($lengthInitialContent / $lengthContent), 2);** $timeTook = (int)((microtime(true) - $startTime) * 1000); $response->headers->add(['X-Html-Compressor' => time() . ': ' . $savedData . '% ' . $timeTook . 'ms']); }

I resolved my error by just adding an empty div-block.

Expected behaviour

No exception ;)

Steps to Reproduce?

create a route that renders a twig file without any content.

tinect commented 3 years ago

Thank you. Fixed in store soon.