MDL-86345 libraries: upgrade to version 1.3.75 of Minify.
This commit is contained in:
@@ -21,8 +21,7 @@
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": ">=2.0",
|
||||
"matthiasmullie/scrapbook": ">=1.3",
|
||||
"phpunit/phpunit": ">=4.8",
|
||||
"squizlabs/php_codesniffer": ">=3.0"
|
||||
"phpunit/phpunit": ">=4.8"
|
||||
},
|
||||
"suggest": {
|
||||
"psr/cache-implementation": "Cache implementation to use with Minify::cache"
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
namespace MatthiasMullie\Minify;
|
||||
|
||||
use MatthiasMullie\Minify\Exceptions\FileImportException;
|
||||
use MatthiasMullie\Minify\Exceptions\PatternMatchException;
|
||||
use MatthiasMullie\PathConverter\Converter;
|
||||
use MatthiasMullie\PathConverter\ConverterInterface;
|
||||
|
||||
@@ -109,8 +110,8 @@ class CSS extends Minify
|
||||
* \@import's will be loaded and their content merged into the original file,
|
||||
* to save HTTP requests.
|
||||
*
|
||||
* @param string $source The file to combine imports for
|
||||
* @param string $content The CSS content to combine imports for
|
||||
* @param string $source The file to combine imports for
|
||||
* @param string $content The CSS content to combine imports for
|
||||
* @param string[] $parents Parent paths, for circular reference checks
|
||||
*
|
||||
* @return string
|
||||
@@ -245,7 +246,7 @@ class CSS extends Minify
|
||||
* @url(image.jpg) images will be loaded and their content merged into the
|
||||
* original file, to save HTTP requests.
|
||||
*
|
||||
* @param string $source The file to import files for
|
||||
* @param string $source The file to import files for
|
||||
* @param string $content The CSS content to import files for
|
||||
*
|
||||
* @return string
|
||||
@@ -296,6 +297,8 @@ class CSS extends Minify
|
||||
* @param string[] $parents Parent paths, for circular reference checks
|
||||
*
|
||||
* @return string The minified data
|
||||
*
|
||||
* @throws PatternMatchException
|
||||
*/
|
||||
public function execute($path = null, $parents = array())
|
||||
{
|
||||
@@ -357,7 +360,7 @@ class CSS extends Minify
|
||||
* (e.g. ../../images/image.gif, if the new CSS file is 1 folder deeper).
|
||||
*
|
||||
* @param ConverterInterface $converter Relative path converter
|
||||
* @param string $content The CSS content to update relative urls for
|
||||
* @param string $content The CSS content to update relative urls for
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -590,6 +593,7 @@ class CSS extends Minify
|
||||
|
||||
// convert `rgb` to `hex`
|
||||
$dec = '([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])';
|
||||
|
||||
return preg_replace_callback(
|
||||
"/rgb\($dec $dec $dec\)/i",
|
||||
function ($match) {
|
||||
@@ -621,10 +625,10 @@ class CSS extends Minify
|
||||
$tag = '(rgb|hsl|hwb|(?:(?:ok)?(?:lch|lab)))';
|
||||
|
||||
// remove alpha channel if it's pointless ..
|
||||
$content = preg_replace('/' . $tag . '\(\s*([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+\/\s+1(?:(?:\.\d?)*|00%)?\s*\)/i', '$1($2 $3 $4)', $content);
|
||||
$content = preg_replace('/' . $tag . '\(\s*([^\s)]+)\s+([^\s)]+)\s+([^\s)]+)\s+\/\s+1(?:(?:\.\d?)*|00%)?\s*\)/i', '$1($2 $3 $4)', $content);
|
||||
|
||||
// replace `transparent` with shortcut ..
|
||||
$content = preg_replace('/' . $tag . '\(\s*[^\s]+\s+[^\s]+\s+[^\s]+\s+\/\s+0(?:[\.0%]*)?\s*\)/i', '#fff0', $content);
|
||||
$content = preg_replace('/' . $tag . '\(\s*[^\s)]+\s+[^\s)]+\s+[^\s)]+\s+\/\s+0(?:[\.0%]*)?\s*\)/i', '#fff0', $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
@@ -732,29 +736,31 @@ class CSS extends Minify
|
||||
* @param string $content The CSS content to strip the whitespace for
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws PatternMatchException
|
||||
*/
|
||||
protected function stripWhitespace($content)
|
||||
{
|
||||
// remove leading & trailing whitespace
|
||||
$content = preg_replace('/^\s*/m', '', $content);
|
||||
$content = preg_replace('/\s*$/m', '', $content);
|
||||
$content = $this->pregReplace('/^\s*/m', '', $content);
|
||||
$content = $this->pregReplace('/\s*$/m', '', $content);
|
||||
|
||||
// replace newlines with a single space
|
||||
$content = preg_replace('/\s+/', ' ', $content);
|
||||
$content = $this->pregReplace('/\s+/', ' ', $content);
|
||||
|
||||
// remove whitespace around meta characters
|
||||
// inspired by stackoverflow.com/questions/15195750/minify-compress-css-with-regex
|
||||
$content = preg_replace('/\s*([\*$~^|]?+=|[{};,>~]|!important\b)\s*/', '$1', $content);
|
||||
$content = preg_replace('/([\[(:>\+])\s+/', '$1', $content);
|
||||
$content = preg_replace('/\s+([\]\)>\+])/', '$1', $content);
|
||||
$content = preg_replace('/\s+(:)(?![^\}]*\{)/', '$1', $content);
|
||||
$content = $this->pregReplace('/\s*([\*$~^|]?+=|[{};,>~]|!important\b)\s*/', '$1', $content);
|
||||
$content = $this->pregReplace('/([\[(:>\+])\s+/', '$1', $content);
|
||||
$content = $this->pregReplace('/\s+([\]\)>\+])/', '$1', $content);
|
||||
$content = $this->pregReplace('/\s+(:)(?![^\}]*\{)/', '$1', $content);
|
||||
|
||||
// whitespace around + and - can only be stripped inside some pseudo-
|
||||
// classes, like `:nth-child(3+2n)`
|
||||
// not in things like `calc(3px + 2px)`, shorthands like `3px -2px`, or
|
||||
// selectors like `div.weird- p`
|
||||
$pseudos = array('nth-child', 'nth-last-child', 'nth-last-of-type', 'nth-of-type');
|
||||
$content = preg_replace('/:(' . implode('|', $pseudos) . ')\(\s*([+-]?)\s*(.+?)\s*([+-]?)\s*(.*?)\s*\)/', ':$1($2$3$4$5)', $content);
|
||||
$content = $this->pregReplace('/:(' . implode('|', $pseudos) . ')\(\s*([+-]?)\s*(.+?)\s*([+-]?)\s*(.*?)\s*\)/', ':$1($2$3$4$5)', $content);
|
||||
|
||||
// remove semicolon/whitespace followed by closing bracket
|
||||
$content = str_replace(';}', '}', $content);
|
||||
@@ -762,6 +768,27 @@ class CSS extends Minify
|
||||
return trim($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a preg_replace and check for errors.
|
||||
*
|
||||
* @param string $pattern Pattern
|
||||
* @param string $replacement Replacement
|
||||
* @param string $subject String to process
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws PatternMatchException
|
||||
*/
|
||||
protected function pregReplace($pattern, $replacement, $subject)
|
||||
{
|
||||
$result = preg_replace($pattern, $replacement, $subject);
|
||||
if ($result === null) {
|
||||
throw PatternMatchException::fromLastError("Failed to replace with pattern '$pattern'");
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all occurrences of functions that may contain math, where
|
||||
* whitespace around operators needs to be preserved (e.g. calc, clamp).
|
||||
|
||||
@@ -17,6 +17,4 @@ namespace MatthiasMullie\Minify;
|
||||
*
|
||||
* @author Matthias Mullie <[email protected]>
|
||||
*/
|
||||
abstract class Exception extends \Exception
|
||||
{
|
||||
}
|
||||
abstract class Exception extends \Exception {}
|
||||
|
||||
@@ -19,6 +19,4 @@ use MatthiasMullie\Minify\Exception;
|
||||
*
|
||||
* @author Matthias Mullie <[email protected]>
|
||||
*/
|
||||
abstract class BasicException extends Exception
|
||||
{
|
||||
}
|
||||
abstract class BasicException extends Exception {}
|
||||
|
||||
@@ -17,6 +17,4 @@ namespace MatthiasMullie\Minify\Exceptions;
|
||||
*
|
||||
* @author Matthias Mullie <[email protected]>
|
||||
*/
|
||||
class FileImportException extends BasicException
|
||||
{
|
||||
}
|
||||
class FileImportException extends BasicException {}
|
||||
|
||||
@@ -17,6 +17,4 @@ namespace MatthiasMullie\Minify\Exceptions;
|
||||
*
|
||||
* @author Matthias Mullie <[email protected]>
|
||||
*/
|
||||
class IOException extends BasicException
|
||||
{
|
||||
}
|
||||
class IOException extends BasicException {}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Pattern match exception.
|
||||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/minify/issues
|
||||
*
|
||||
* @author Ere Maijala <[email protected]>
|
||||
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
namespace MatthiasMullie\Minify\Exceptions;
|
||||
|
||||
/**
|
||||
* Pattern Match Exception Class.
|
||||
*
|
||||
* @author Ere Maijala <[email protected]>
|
||||
*/
|
||||
class PatternMatchException extends BasicException
|
||||
{
|
||||
/**
|
||||
* Create an exception from preg_last_error.
|
||||
*
|
||||
* @param string $msg Error message
|
||||
*/
|
||||
public static function fromLastError($msg)
|
||||
{
|
||||
$msg .= ': Error ' . preg_last_error();
|
||||
if (PHP_MAJOR_VERSION >= 8) {
|
||||
$msg .= ' - ' . preg_last_error_msg();
|
||||
}
|
||||
|
||||
return new PatternMatchException($msg);
|
||||
}
|
||||
}
|
||||
@@ -450,7 +450,7 @@ class JS extends Minify
|
||||
* This will prepare the given array by escaping all characters.
|
||||
*
|
||||
* @param string[] $operators
|
||||
* @param string $delimiter
|
||||
* @param string $delimiter
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
@@ -481,7 +481,7 @@ class JS extends Minify
|
||||
* This will prepare the given array by escaping all characters.
|
||||
*
|
||||
* @param string[] $keywords
|
||||
* @param string $delimiter
|
||||
* @param string $delimiter
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
namespace MatthiasMullie\Minify;
|
||||
|
||||
use MatthiasMullie\Minify\Exceptions\IOException;
|
||||
use MatthiasMullie\Minify\Exceptions\PatternMatchException;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
|
||||
/**
|
||||
@@ -230,7 +231,7 @@ abstract class Minify
|
||||
* Save to file.
|
||||
*
|
||||
* @param string $content The minified data
|
||||
* @param string $path The path to save the minified data to
|
||||
* @param string $path The path to save the minified data to
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@@ -249,7 +250,7 @@ abstract class Minify
|
||||
* If $replacement is a string, it must be plain text. Placeholders like $1 or \2 don't work.
|
||||
* If you need that functionality, use a callback instead.
|
||||
*
|
||||
* @param string $pattern PCRE pattern
|
||||
* @param string $pattern PCRE pattern
|
||||
* @param string|callable $replacement Replacement value for matched pattern
|
||||
*/
|
||||
protected function registerPattern($pattern, $replacement = '')
|
||||
@@ -265,23 +266,9 @@ abstract class Minify
|
||||
*/
|
||||
protected function stripMultilineComments()
|
||||
{
|
||||
// First extract comments we want to keep, so they can be restored later
|
||||
// PHP only supports $this inside anonymous functions since 5.4
|
||||
$minifier = $this;
|
||||
$callback = function ($match) use ($minifier) {
|
||||
$count = count($minifier->extracted);
|
||||
$placeholder = '/*' . $count . '*/';
|
||||
$minifier->extracted[$placeholder] = $match[0];
|
||||
|
||||
return $placeholder;
|
||||
};
|
||||
$this->registerPattern('/
|
||||
# optional newline
|
||||
\n?
|
||||
|
||||
# start comment
|
||||
\/\*
|
||||
|
||||
// Pattern for matching comments that we want to preserve
|
||||
$keepPattern = '/^
|
||||
# comment content
|
||||
(?:
|
||||
# either starts with an !
|
||||
@@ -293,14 +280,24 @@ abstract class Minify
|
||||
# there is either a @license or @preserve tag
|
||||
@(?:license|preserve)
|
||||
)
|
||||
/ixs';
|
||||
$callback = function ($match) use ($minifier, $keepPattern) {
|
||||
if (preg_match($keepPattern, $match[1])) {
|
||||
// Preserve the comment
|
||||
$count = count($minifier->extracted);
|
||||
$placeholder = '/*' . $count . '*/';
|
||||
$minifier->extracted[$placeholder] = $match[0];
|
||||
} else {
|
||||
// Discard the comment but keep any single line feed
|
||||
$placeholder = strncmp($match[0], "\n", 1) === 0 || substr($match[0], -1) === "\n"
|
||||
? "\n"
|
||||
: '';
|
||||
}
|
||||
|
||||
# then match to the end of the comment
|
||||
.*?\*\/\n?
|
||||
return $placeholder;
|
||||
};
|
||||
|
||||
/ixs', $callback);
|
||||
|
||||
// Then strip all other comments
|
||||
$this->registerPattern('/\/\*.*?\*\//s', '');
|
||||
$this->registerPattern('/\n?\/\*(.*?)\*\/\n?/s', $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -314,6 +311,8 @@ abstract class Minify
|
||||
* @param string $content The content to replace patterns in
|
||||
*
|
||||
* @return string The (manipulated) content
|
||||
*
|
||||
* @throws PatternMatchException
|
||||
*/
|
||||
protected function replace($content)
|
||||
{
|
||||
@@ -341,7 +340,8 @@ abstract class Minify
|
||||
}
|
||||
|
||||
$match = null;
|
||||
if (preg_match($pattern, $content, $match, PREG_OFFSET_CAPTURE, $processedOffset)) {
|
||||
$matchResult = preg_match($pattern, $content, $match, PREG_OFFSET_CAPTURE, $processedOffset);
|
||||
if ($matchResult) {
|
||||
$matches[$i] = $match;
|
||||
|
||||
// we'll store the match position as well; that way, we
|
||||
@@ -349,6 +349,11 @@ abstract class Minify
|
||||
// the first (we'll still know where those others are)
|
||||
$positions[$i] = $match[0][1];
|
||||
} else {
|
||||
if ($matchResult === false) {
|
||||
throw PatternMatchException::fromLastError(
|
||||
"Failed to match pattern '$pattern' at $processedOffset"
|
||||
);
|
||||
}
|
||||
// if the pattern couldn't be matched, there's no point in
|
||||
// executing it again in later runs on this same content;
|
||||
// ignore this one until we reach end of content
|
||||
@@ -390,7 +395,7 @@ abstract class Minify
|
||||
* If it's a string, just pass it through.
|
||||
*
|
||||
* @param string|callable $replacement Replacement value
|
||||
* @param array $match Match data, in PREG_OFFSET_CAPTURE form
|
||||
* @param array $match Match data, in PREG_OFFSET_CAPTURE form
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -445,6 +450,11 @@ abstract class Minify
|
||||
};
|
||||
|
||||
/*
|
||||
* Quantifier {0,65535} is used instead of *? to avoid exceeding
|
||||
* backtrack limit with large strings. 65535 is the maximum allowed
|
||||
* (see https://www.php.net/manual/en/regexp.reference.repetition.php)
|
||||
* and should be well sufficient for string representations here.
|
||||
*
|
||||
* The \\ messiness explained:
|
||||
* * Don't count ' or " as end-of-string if it's escaped (has backslash
|
||||
* in front of it)
|
||||
@@ -456,7 +466,8 @@ abstract class Minify
|
||||
* considered as escape-char (times 2) and to get it in the regex,
|
||||
* escaped (times 2)
|
||||
*/
|
||||
$this->registerPattern('/([' . $chars . '])(.*?(?<!\\\\)(\\\\\\\\)*+)\\1/s', $callback);
|
||||
|
||||
$this->registerPattern('/([' . $chars . '])(.{0,65535}?(?<!\\\\)(\\\\\\\\)*+)\\1/s', $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -532,8 +543,8 @@ abstract class Minify
|
||||
* Attempts to write $content to the file specified by $handler. $path is used for printing exceptions.
|
||||
*
|
||||
* @param resource $handler The resource to write to
|
||||
* @param string $content The content to write
|
||||
* @param string $path The path to the file (for exception printing only)
|
||||
* @param string $content The content to write
|
||||
* @param string $path The path to the file (for exception printing only)
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
<location>minify/matthiasmullie-minify</location>
|
||||
<name>MatthiasMullie\Minify</name>
|
||||
<description>CSS & JavaScript minifier, in PHP</description>
|
||||
<version>1.3.73</version>
|
||||
<version>1.3.75</version>
|
||||
<license>MIT</license>
|
||||
<repository>https://github.com/matthiasmullie/minify</repository>
|
||||
<customised/>
|
||||
|
||||
Reference in New Issue
Block a user