Skip to content

Commit

Permalink
Don't leave behind trailing semicolons when moving imports to top
Browse files Browse the repository at this point in the history
Fixes #240
  • Loading branch information
matthiasmullie committed Apr 4, 2018
1 parent 473896b commit 81d3a80
Show file tree
Hide file tree
Showing 2 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 @@ -86,7 +86,7 @@ public function setImportExtensions(array $extensions)
*/
protected function moveImportsToTop($content)
{
if (preg_match_all('/(;?)(@import (?<url>url\()?(?P<quotes>["\']?).+?(?P=quotes)(?(url)\)))/', $content, $matches)) {
if (preg_match_all('/(;?)(@import (?<url>url\()?(?P<quotes>["\']?).+?(?P=quotes)(?(url)\)));?/', $content, $matches)) {
// remove from content
foreach ($matches[0] as $import) {
$content = str_replace($import, '', $content);
Expand Down
14 changes: 14 additions & 0 deletions tests/css/CSSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,20 @@ public function dataProvider()
'#site-header.medium-header .top-col.logo-col{-webkit-flex:auto 0 0;flex:auto 0 0}',
);

// https://github.com/matthiasmullie/minify/issues/240
$tests[] = array(
'p{color:red}
@import url("http://minify.dev/?a=1&amp;b=some/*lala*/thing");
body{font-family:sans-serif}',
'@import url(http://minify.dev/?a=1&amp;b=some/*lala*/thing);p{color:red}body{font-family:sans-serif}',
);
$tests[] = array(
'p{color:red}
@import url("http://minify.dev/?a=1&amp;b=some/*lala*/thing") ;
body{font-family:sans-serif}',
'@import url(http://minify.dev/?a=1&amp;b=some/*lala*/thing);p{color:red}body{font-family:sans-serif}',
);

return $tests;
}

Expand Down

0 comments on commit 81d3a80

Please sign in to comment.