minify
minify copied to clipboard
Nth-child with spaces inside gets broken
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);
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*\)/'