matthiasmullie / minify

CSS & JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.
https://matthiasmullie.github.io/minify/
MIT License
1.97k stars 309 forks source link

JS whiteSpace removes the whole script #419

Open mitsh opened 8 months ago

mitsh commented 8 months ago

latest version of the minify js, removes all the datatables script on the step of whiteSpace cleaning.

I track down the script line by line, found the for-loop part that removes all the content.

$content = preg_replace('/(for\((?:[^;\{]*|[^;\{]*function[^;\{]*(\{([^\{\}]*(?-2))*[^\{\}]*\})?[^;\{]*);[^;\{]*;[^;\{]*\));(\}|$)/s', '\\1;;\\4', $content);

I just modified the line to prevent the script being emptied.

$old_content = $content;
        $content = preg_replace('/(for\((?:[^;\{]*|[^;\{]*function[^;\{]*(\{([^\{\}]*(?-2))*[^\{\}]*\})?[^;\{]*);[^;\{]*;[^;\{]*\));(\}|$)/s', '\\1;;\\4', $content);
        if (empty($content))
        {
            $content = $old_content;
        }