diff --git a/src/CSS.php b/src/CSS.php index 1b354ad..9226df2 100644 --- a/src/CSS.php +++ b/src/CSS.php @@ -740,7 +740,7 @@ protected function extractCustomProperties() // PHP only supports $this inside anonymous functions since 5.4 $minifier = $this; $this->registerPattern( - '/(?<=^|[;}])(--[^:;{}"\'\s]+)\s*:([^;{}]+)/m', + '/(?<=^|[;}])\s*(--[^:;{}"\'\s]+)\s*:([^;{}]+)/m', function ($match) use ($minifier) { $placeholder = '--custom-'. count($minifier->extracted) . ':0'; $minifier->extracted[$placeholder] = $match[1] .':'. trim($match[2]); diff --git a/tests/css/CSSTest.php b/tests/css/CSSTest.php index 6f576f5..4f300b5 100644 --- a/tests/css/CSSTest.php +++ b/tests/css/CSSTest.php @@ -832,6 +832,17 @@ public function dataProvider() ':root{--some-var:0px}.some-class{margin-left:calc(20px + var(--some-var))}', ); + // https://github.com/matthiasmullie/minify/issues/378 + $tests[] = array( + ':root { + --some-var: 0px; +} +p { +margin-left: calc(20px + var(--some-var)); +}', + ':root{--some-var:0px}p{margin-left:calc(20px + var(--some-var))}' + ); + return $tests; }