From 759f0871f71262f898ad9a30c0907ce8b11876b0 Mon Sep 17 00:00:00 2001 From: rowhel95 Date: Wed, 23 Mar 2022 17:54:08 +0100 Subject: [PATCH 1/2] Fix minified CSS variable with leading whitespaces Fixes #378 --- src/CSS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]); From 6fbbb7455a31483ccf0985d9b6748645b307c38b Mon Sep 17 00:00:00 2001 From: Matthias Mullie Date: Thu, 24 Mar 2022 09:54:46 +0100 Subject: [PATCH 2/2] Add test for #378 --- tests/css/CSSTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) 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; }