mirror of
https://github.com/matthiasmullie/minify.git
synced 2025-02-23 12:43:22 +01:00
Limit what zeroes can be truncated
This commit is contained in:
parent
609c6f4cfc
commit
e13143b35c
13
src/CSS.php
13
src/CSS.php
@ -525,18 +525,21 @@ class CSS extends Minify
|
||||
protected function shortenZeroes($content)
|
||||
{
|
||||
// strip 0-digits (.0 -> 0, 50.00 -> 50)
|
||||
// no risk of stripping selectors, a class name can't start with a digit
|
||||
$content = preg_replace('/(?<![0-9])\.0+(?![1-9])/', '0', $content);
|
||||
$content = preg_replace('/\.0+(?![1-9])/', '', $content);
|
||||
|
||||
// truncate zeroes (00 -> 0) (can't be preceded by # for #000 colors)
|
||||
$content = preg_replace('/(?<![#0-9])0+(?![1-9])/', '0', $content);
|
||||
|
||||
// strip negative zeroes (-0 -> 0)
|
||||
$content = preg_replace('/(?<![0-9])-0(?![\.0-9])/', '0', $content);
|
||||
$content = preg_replace('/(?<![0-9])-0+(?![\.1-9])/', '0', $content);
|
||||
|
||||
// strip units after zeroes (0px -> 0)
|
||||
$units = array('em', 'ex', '%', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'ch', 'rem', 'vh', 'vw', 'vmin', 'vmax', 'vm');
|
||||
$content = preg_replace('/(?<![0-9])0(' . implode('|', $units) . ')/', '0', $content);
|
||||
$content = preg_replace('/(?<![0-9])0+(' . implode('|', $units) . ')/', '0', $content);
|
||||
|
||||
// truncate zeroes (00 -> 0) (can't be preceded by # for #000 colors)
|
||||
// only before & after certain characters, to ensure we don't truncate
|
||||
// zeroes in e.g. #000 or selectors
|
||||
$content = preg_replace('/(?<=[ :\(])0+(?=[ :\)])/', '0', $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
@ -219,6 +219,14 @@ margin-left: -0.3125rem;
|
||||
'p { margin: .0; }',
|
||||
'p{margin:0}',
|
||||
);
|
||||
$tests[] = array(
|
||||
'p { margin: 00px; }',
|
||||
'p{margin:0}',
|
||||
);
|
||||
$tests[] = array(
|
||||
'p.class00 { background-color: #000000; color: #000; }',
|
||||
'p.class00{background-color:#000;color:#000}',
|
||||
);
|
||||
|
||||
// https://github.com/matthiasmullie/minify/issues/24
|
||||
$tests[] = array(
|
||||
|
Loading…
x
Reference in New Issue
Block a user