Skip to content

Commit 76ba4a5

Browse files
EreMaijalamatthiasmullie
authored andcommitted
Fix handling of decimal numbers in cleanupModernColors.
1 parent 7f9ac62 commit 76ba4a5

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/CSS.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,10 @@ protected function cleanupModernColors($content)
625625
$tag = '(rgb|hsl|hwb|(?:(?:ok)?(?:lch|lab)))';
626626

627627
// remove alpha channel if it's pointless ..
628-
$content = preg_replace('/' . $tag . '\(\s*([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+\/\s+1(?:(?:\.\d?)*|00%)?\s*\)/i', '$1($2 $3 $4)', $content);
628+
$content = preg_replace('/' . $tag . '\(\s*([^\s)]+)\s+([^\s)]+)\s+([^\s)]+)\s+\/\s+1(?:(?:\.\d?)*|00%)?\s*\)/i', '$1($2 $3 $4)', $content);
629629

630630
// replace `transparent` with shortcut ..
631-
$content = preg_replace('/' . $tag . '\(\s*[^\s]+\s+[^\s]+\s+[^\s]+\s+\/\s+0(?:[\.0%]*)?\s*\)/i', '#fff0', $content);
631+
$content = preg_replace('/' . $tag . '\(\s*[^\s)]+\s+[^\s)]+\s+[^\s)]+\s+\/\s+0(?:[\.0%]*)?\s*\)/i', '#fff0', $content);
632632

633633
return $content;
634634
}

tests/CSS/CSSTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,24 @@ public static function dataProvider()
902902
'.a1::after{content:"2"}.a1::after{content:"1"}',
903903
);
904904

905+
// https://github.com/matthiasmullie/minify/issues/435 - cleanupModernColors
906+
$tests[] = array(
907+
'.test{color:rgb(1,2,3);background-color:rgba(4,5,6,7)}',
908+
'.test{color:#010203;background-color:rgba(4,5,6,7)}',
909+
);
910+
$tests[] = array(
911+
'.test{color:rgb(1, 2, 3); background-color:rgba(4, 5, 6, 7)}',
912+
'.test{color:#010203;background-color:rgba(4,5,6,7)}',
913+
);
914+
$tests[] = array(
915+
'.test2{color:rgb(1.5,2.5,3.5);background-color:rgba(0,0,0,0)}',
916+
'.test2{color:rgb(1.5,2.5,3.5);background-color:#fff0}',
917+
);
918+
$tests[] = array(
919+
'.test2 { color: rgb(1.5 , 2.5, 3.5); background-color: rgba(0,0, 0,0)}',
920+
'.test2{color:rgb(1.5,2.5,3.5);background-color:#fff0}',
921+
);
922+
905923
return $tests;
906924
}
907925

0 commit comments

Comments
 (0)