tubalmartin / YUI-CSS-compressor-PHP-port

A PHP port of the YUI CSS compressor.
230 stars 34 forks source link

"JIT stack limit exhausted" error encountered for certain styles #65

Open trepmal opened 1 year ago

trepmal commented 1 year ago

Here's my CSS, reduced/simplified from a real-world example: https://gist.github.com/trepmal/edf83dbd0d10b949b353c4b88fe20eea . The key elements being the selector with escaped characters, and a certain minimum amount of styles to follow.

When run through the minifier, nothing is returned:

use tubalmartin\CssMin\Minifier as CSSmin;

$css = file_get_contents( 'test.css' );

$minifier = new CSSmin;
$min = $minifier->run( $css );

// $min is empty

There "JIT stack limit exhausted" error comes from https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port/blob/3cbf557f4079d83a06f9c3ff9b957c022d7805cf/src/Minifier.php#L322-L327

Which can be tested directly:

$min_test = preg_replace_callback(
    '/(?:"(?:[^\\\\"]|\\\\.|\\\\)*")|'."(?:'(?:[^\\\\']|\\\\.|\\\\)*')/S",
    function($i) { return $i; },
    $css
);

if ( preg_last_error() ) {
    echo preg_last_error_msg() . PHP_EOL;
}