Skip to content

Commit

Permalink
Fix bug #395 Calc function missing on background-position property
Browse files Browse the repository at this point in the history
  • Loading branch information
simondud committed Aug 1, 2022
1 parent d8993df commit a61c949
Show file tree
Hide file tree
Showing 3 changed files with 15 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 @@ -722,7 +722,7 @@ protected function extractMath()
// and since we've captured more code than required, we may have some leftover
// calc() in here too - go recursive on the remaining but of code to go figure
// that out and extract what is needed
$rest = str_replace($function.$expr, '', $match[0]);
$rest = $minifier->str_replace_first($function.$expr, '', $match[0]);
$rest = preg_replace_callback($pattern, $callback, $rest);

return $placeholder.$rest;
Expand Down
8 changes: 8 additions & 0 deletions src/Minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,4 +494,12 @@ protected function writeToFile($handler, $content, $path = '')
throw new IOException('The file "'.$path.'" could not be written to. Check your disk space and file permissions.');
}
}

protected static function str_replace_first($search, $replace, $subject) {
$pos = strpos($subject, $search);
if ($pos !== false) {
return substr_replace($subject, $replace, $pos, strlen($search));
}
return $subject;
}
}
6 changes: 6 additions & 0 deletions tests/css/CSSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,12 @@ public function dataProvider()
'.stk-block-columns>.stk-block-content{--stk-column-gap:0px;column-gap:var(--stk-column-gap,0)}'
);

// https://github.com/matthiasmullie/minify/issues/395
$tests[] = array(
'background-position: right 0.8em bottom calc(50% - 5px), right 0.8em top calc(50% - 5px);',
'background-position:right .8em bottom calc(50% - 5px),right .8em top calc(50% - 5px);'
);

return $tests;
}

Expand Down

0 comments on commit a61c949

Please sign in to comment.