diff --git a/lib/minify/matthiasmullie-minify/src/CSS.php b/lib/minify/matthiasmullie-minify/src/CSS.php
index ab0de8caa1f..09cedeee3a0 100644
--- a/lib/minify/matthiasmullie-minify/src/CSS.php
+++ b/lib/minify/matthiasmullie-minify/src/CSS.php
@@ -632,46 +632,7 @@ class CSS extends Minify
*/
protected function stripComments()
{
- // 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;
- };
- // Moodle-specific change MDL-68191 starts.
- /* This was the old code:
- $this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
- */
- // This is the new, more accurate and faster regex.
- $this->registerPattern('/
- # optional newline
- \n?
-
- # start comment
- \/\*
-
- # comment content
- (?:
- # either starts with an !
- !
- |
- # or, after some number of characters which do not end the comment
- (?:(?!\*\/).)*?
-
- # there is either a @license or @preserve tag
- @(?:license|preserve)
- )
-
- # then match to the end of the comment
- .*?\*\/\n?
-
- /ixs', $callback);
- // Moodle-specific change MDL-68191.
-
- $this->registerPattern('/\/\*.*?\*\//s', '');
+ $this->stripMultilineComments();
}
/**
diff --git a/lib/minify/matthiasmullie-minify/src/JS.php b/lib/minify/matthiasmullie-minify/src/JS.php
index ac5e98dd92e..d592b08bb33 100644
--- a/lib/minify/matthiasmullie-minify/src/JS.php
+++ b/lib/minify/matthiasmullie-minify/src/JS.php
@@ -198,28 +198,7 @@ class JS extends Minify
*/
protected function stripComments()
{
- // PHP only supports $this inside anonymous functions since 5.4
- $minifier = $this;
- $callback = function ($match) use ($minifier) {
- if (
- substr($match[2], 0, 1) === '!' ||
- strpos($match[2], '@license') !== false ||
- strpos($match[2], '@preserve') !== false
- ) {
- // preserve multi-line comments that start with /*!
- // or contain @license or @preserve annotations
- $count = count($minifier->extracted);
- $placeholder = '/*' . $count . '*/';
- $minifier->extracted[$placeholder] = $match[0];
-
- return $match[1] . $placeholder . $match[3];
- }
-
- return $match[1] . $match[3];
- };
-
- // multi-line comments
- $this->registerPattern('/(\n?)\/\*(.*?)\*\/(\n?)/s', $callback);
+ $this->stripMultilineComments();
// single-line comments
$this->registerPattern('/\/\/.*$/m', '');
diff --git a/lib/minify/matthiasmullie-minify/src/Minify.php b/lib/minify/matthiasmullie-minify/src/Minify.php
index 19faf988601..f77478bebb7 100644
--- a/lib/minify/matthiasmullie-minify/src/Minify.php
+++ b/lib/minify/matthiasmullie-minify/src/Minify.php
@@ -260,6 +260,49 @@ abstract class Minify
$this->patterns[] = array($pattern, $replacement);
}
+ /**
+ * Both JS and CSS use the same form of multi-line comment, so putting the common code here.
+ */
+ 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
+ \/\*
+
+ # comment content
+ (?:
+ # either starts with an !
+ !
+ |
+ # or, after some number of characters which do not end the comment
+ (?:(?!\*\/).)*?
+
+ # there is either a @license or @preserve tag
+ @(?:license|preserve)
+ )
+
+ # then match to the end of the comment
+ .*?\*\/\n?
+
+ /ixs', $callback);
+
+ // Then strip all other comments
+ $this->registerPattern('/\/\*.*?\*\//s', '');
+ }
+
/**
* We can't "just" run some regular expressions against JavaScript: it's a
* complex language. E.g. having an occurrence of // xyz would be a comment,
diff --git a/lib/minify/readme_moodle.txt b/lib/minify/readme_moodle.txt
index 10ec71b21da..dc1ae657cff 100644
--- a/lib/minify/readme_moodle.txt
+++ b/lib/minify/readme_moodle.txt
@@ -15,10 +15,4 @@ mv path-converter-A.B.C/src/ /path/to/moodle/lib/minify/matthiasmullie-pathconve
3) Apply the following patches:
-MDL-68191: https://github.com/matthiasmullie/minify/issues/317 is a bug that stops
- large sections of the CSS from being minimised, and also is a huge performance drain.
- We have applied the fix sent upstream because the performance win is so big.
- (E.g. one case I measured, with the bug was 40 seconds to minify CSS, with the fix was
- a few seconds. This is one of the reasons Behat runs in the browser are so slow.)
- Whenever this library is updated check if the fix is included and remove this note.
- NOTE: As of 2020/12/08, only the first commit was brought into Moodle
+N/A
diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml
index 9b6d7e60162..af59a103362 100644
--- a/lib/thirdpartylibs.xml
+++ b/lib/thirdpartylibs.xml
@@ -82,7 +82,7 @@
minify/matthiasmullie-minify
MatthiasMullie\Minify
CSS & JavaScript minifier, in PHP
- 1.3.70
+ 1.3.71
MIT
https://github.com/matthiasmullie/minify