minify icon indicating copy to clipboard operation
minify copied to clipboard

Nth-child with spaces inside gets broken

Open roby65 opened this issue 1 year ago • 1 comments

We have this code in our css:

nth-child(1 of :not([class*=hero]))

This gets minified to:

nth-child(1of :not([class*=hero]))

Breaking it.

The code that breaks this is in CSS.PHP line 757:

$content = preg_replace('/:(' . implode('|', $pseudos) . ')\(\s*([+-]?)\s*(.+?)\s*([+-]?)\s*(.*?)\s*\)/', ':$1($2$3$4$5)', $content);

roby65 avatar Jul 10 '24 14:07 roby65

Quick fix for those that need it: Replace (.*?) in line 757 of vendor/matthiasmullie/minify/src/CSS.php:756 with ((?:(?!of).)*), or use your own class that extends the CSS-class and override the stripWhitespace in there.

This is negative lookup and won't remove the whitespaces before "of".

@matthiasmullie can you integrate this and push a new version? Or do you need a PR with tests?

// I hade issues with the negative lookup. This pattern seems to work better: '/:(' . implode('|', $pseudos) . ')\(\s*([+-]?)\s*(.+?)\s*([+-]?)\s*(\s+of\s+[^\)]+)?\s*\)/'

fabian-mcfly avatar Mar 25 '25 14:03 fabian-mcfly