Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1322 from Reconix/patch-1
Browse files Browse the repository at this point in the history
Update CSSmin to v3.0.6
  • Loading branch information
lonnieezell committed Dec 17, 2019
2 parents 154aa0d + 95efd56 commit 3eaf6f8
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions bonfire/libraries/CSSMin.php
Expand Up @@ -2,7 +2,7 @@
/**
* @package Bonfire\Libraries\CSSMin
* @link https://github.com/natxet/CssMin
* @version 3.0.3
* @version 3.0.6
*/
/**
* CssMin - A (simple) css minifier with benefits
Expand Down Expand Up @@ -470,7 +470,7 @@ public function __toString()
}
elseif ($class === "CssAtKeyframesStartToken")
{
$r[] = $indent . "@keyframes \"" . $token->Name . "\"";
$r[] = $indent . "@keyframes " . $token->Name;
$r[] = $this->indent . $indent . "{";
$level++;
}
Expand Down Expand Up @@ -498,10 +498,10 @@ public function __toString()
$r[] = $this->indent . $indent . "{";
$level++;
}
elseif ($class == "CssAtFontFaceDeclarationToken"
elseif ($class === "CssAtFontFaceDeclarationToken"
|| $class === "CssAtKeyframesRulesetDeclarationToken"
|| $class === "CssAtPageDeclarationToken"
|| $class == "CssAtVariablesDeclarationToken"
|| $class === "CssAtVariablesDeclarationToken"
|| $class === "CssRulesetDeclarationToken"
)
{
Expand Down Expand Up @@ -1349,6 +1349,13 @@ public function apply(array &$tokens)
*/
class CssRemoveCommentsMinifierFilter extends aCssMinifierFilter
{
/**
* Regular expression whitelisting any important comments to preserve.
*
* @var string
*/
private $whitelistPattern = '/(^\/\*!|@preserve|copyright|license|author|https?:|www\.)/i';

/**
* Implements {@link aCssMinifierFilter::filter()}.
*
Expand All @@ -1362,8 +1369,11 @@ public function apply(array &$tokens)
{
if (get_class($tokens[$i]) === "CssCommentToken")
{
$tokens[$i] = null;
$r++;
if (!preg_match($this->whitelistPattern, $tokens[$i]->Comment))
{
$tokens[$i] = null;
$r++;
}
}
}
return $r;
Expand Down Expand Up @@ -1657,6 +1667,20 @@ public function parse($source)
}
}
$buffer .= $c;

// Fix case when value of url() contains parentheses, for example: url("data: ... ()")
if ($this->getState() == 'T_URL' && $c == ')') {
$trimmedBuffer = trim($buffer);
if (preg_match('@url\((\s+)?".+@', $trimmedBuffer)
&& !preg_match('@url\((\s+)?".+"\)@', $trimmedBuffer)
|| preg_match('@url\((\s+)?\'.+@', $trimmedBuffer)
&& !preg_match('@url\((\s+)?\'.+\'\)@', $trimmedBuffer)
) {
$p = $c; // Set the parent char
continue;
}
}

// Extended processing only if the current char is a global trigger char
if (strpos($globalTriggerChars, $c) !== false)
{
Expand Down Expand Up @@ -1845,7 +1869,7 @@ public function __toString()
}
elseif ($class === "CssAtKeyframesStartToken")
{
$r[] = $indent . "@keyframes \"" . $token->Name . "\" {";
$r[] = $indent . "@keyframes " . $token->Name . " {";
$level++;
}
elseif ($class === "CssAtMediaStartToken")
Expand Down Expand Up @@ -2224,8 +2248,9 @@ public static function initialise()
{
// Create the class index for autoloading or including
$paths = array(dirname(__FILE__));
while (list($i, $path) = each($paths))
for ($i = 0; $i < count($paths); $i++)
{
$path = $paths[$i];
$subDirectorys = glob($path . "*", GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT);
if (is_array($subDirectorys))
{
Expand Down Expand Up @@ -2389,7 +2414,7 @@ public function apply(array &$tokens)
$import[$ii]->MediaTypes = $tokens[$i]->MediaTypes;
}
// @import at-rule defineds one or more media types; filter out media types not matching with the parent @import at-rule
elseif (count($import[$ii]->MediaTypes > 0))
elseif (count($import[$ii]->MediaTypes) > 0)
{
foreach ($import[$ii]->MediaTypes as $index => $mediaType)
{
Expand Down Expand Up @@ -4472,7 +4497,7 @@ public function __toString()
{
return "@-moz-keyframes " . $this->Name . " {";
}
return "@" . $this->AtRuleName . " \"" . $this->Name . "\"{";
return "@" . $this->AtRuleName . " " . $this->Name . "{";
}
}

Expand Down

0 comments on commit 3eaf6f8

Please sign in to comment.