fahlisaputra / laravel-minify

Minify your blade views, html, css and obfuscate js files on the fly. Lightweight minifier for your Laravel project.
MIT License
76 stars 17 forks source link

REGEX_VALID_HTML failing due to Catastrophic Backtracking #20

Open TBaker3 opened 8 months ago

TBaker3 commented 8 months ago

Had to dig to find why this package wasn't running.

Turns out the following function was returning false due to Catastrophic Backtracking

    protected function validHtml(string $value): bool
    {
        return (bool) preg_match(self::REGEX_VALID_HTML, $value);
    }
fahlisaputra commented 8 months ago

Hi, Minify for Laravel try to check if it's a valid html structure. It become valid when the structure have head and body section. For example:

<html>
   <head>
      <!-- head -->
   </head>
   <body>
      <!-- body -->
   </body>
</html>

If the structure have any spaces or doesnt have head or body section, it wont work, like this:

< html>
   <head>
      <!-- head -->
   </head>
   <body>
      <!-- body -->
   </body>
</ html>

<html>
   <head>
      <!-- head -->
   </head>
</html>
TBaker3 commented 8 months ago

image Here is my template.

Still not working

andkom commented 1 month ago

have the same issue, on long html pages. html is 100% valid