Skip to content

Commit

Permalink
Make sure math methods extraction checks for word boundaries
Browse files Browse the repository at this point in the history
Otherwise, 'max' could be confused with 'minmax'

Fixes #356
  • Loading branch information
matthiasmullie committed Jan 6, 2021
1 parent 227f190 commit b88dcc6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/CSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ protected function stripWhitespace($content)
protected function extractMath()
{
$functions = array('calc', 'clamp', 'min', 'max');
$pattern = '/('. implode('|', $functions) .')(\(.+?)(?=$|;|})/m';
$pattern = '/\b('. implode('|', $functions) .')(\(.+?)(?=$|;|})/m';

// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
Expand Down
6 changes: 6 additions & 0 deletions tests/css/CSSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,12 @@ public function dataProvider()
'.space-x-4>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-right:calc(1rem * var(--tw-space-x-reverse));margin-left:calc(1rem * calc(1 - var(--tw-space-x-reverse)))}',
);

// https://github.com/matthiasmullie/minify/issues/356
$tests[] = array(
'.testclass{ grid-template-columns:minmax(0,1fr) minmax(0,1fr) minmax(0,1fr); }',
'.testclass{grid-template-columns:minmax(0,1fr) minmax(0,1fr) minmax(0,1fr)}',
);

return $tests;
}

Expand Down

0 comments on commit b88dcc6

Please sign in to comment.