Skip to content

Commit f0efcf9

Browse files
committedDec 18, 2023
MDL-79663 libraries: upgrade to version 1.3.71 of Minify.
1 parent 513f3b0 commit f0efcf9

File tree

5 files changed

+47
-70
lines changed

5 files changed

+47
-70
lines changed
 

‎lib/minify/matthiasmullie-minify/src/CSS.php

+1-40
Original file line numberDiff line numberDiff line change
@@ -632,46 +632,7 @@ protected function stripEmptyTags($content)
632632
*/
633633
protected function stripComments()
634634
{
635-
// PHP only supports $this inside anonymous functions since 5.4
636-
$minifier = $this;
637-
$callback = function ($match) use ($minifier) {
638-
$count = count($minifier->extracted);
639-
$placeholder = '/*' . $count . '*/';
640-
$minifier->extracted[$placeholder] = $match[0];
641-
642-
return $placeholder;
643-
};
644-
// Moodle-specific change MDL-68191 starts.
645-
/* This was the old code:
646-
$this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
647-
*/
648-
// This is the new, more accurate and faster regex.
649-
$this->registerPattern('/
650-
# optional newline
651-
\n?
652-
653-
# start comment
654-
\/\*
655-
656-
# comment content
657-
(?:
658-
# either starts with an !
659-
!
660-
|
661-
# or, after some number of characters which do not end the comment
662-
(?:(?!\*\/).)*?
663-
664-
# there is either a @license or @preserve tag
665-
@(?:license|preserve)
666-
)
667-
668-
# then match to the end of the comment
669-
.*?\*\/\n?
670-
671-
/ixs', $callback);
672-
// Moodle-specific change MDL-68191.
673-
674-
$this->registerPattern('/\/\*.*?\*\//s', '');
635+
$this->stripMultilineComments();
675636
}
676637

677638
/**

‎lib/minify/matthiasmullie-minify/src/JS.php

+1-22
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,7 @@ public function execute($path = null)
198198
*/
199199
protected function stripComments()
200200
{
201-
// PHP only supports $this inside anonymous functions since 5.4
202-
$minifier = $this;
203-
$callback = function ($match) use ($minifier) {
204-
if (
205-
substr($match[2], 0, 1) === '!' ||
206-
strpos($match[2], '@license') !== false ||
207-
strpos($match[2], '@preserve') !== false
208-
) {
209-
// preserve multi-line comments that start with /*!
210-
// or contain @license or @preserve annotations
211-
$count = count($minifier->extracted);
212-
$placeholder = '/*' . $count . '*/';
213-
$minifier->extracted[$placeholder] = $match[0];
214-
215-
return $match[1] . $placeholder . $match[3];
216-
}
217-
218-
return $match[1] . $match[3];
219-
};
220-
221-
// multi-line comments
222-
$this->registerPattern('/(\n?)\/\*(.*?)\*\/(\n?)/s', $callback);
201+
$this->stripMultilineComments();
223202

224203
// single-line comments
225204
$this->registerPattern('/\/\/.*$/m', '');

‎lib/minify/matthiasmullie-minify/src/Minify.php

+43
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,49 @@ protected function registerPattern($pattern, $replacement = '')
260260
$this->patterns[] = array($pattern, $replacement);
261261
}
262262

263+
/**
264+
* Both JS and CSS use the same form of multi-line comment, so putting the common code here.
265+
*/
266+
protected function stripMultilineComments()
267+
{
268+
// First extract comments we want to keep, so they can be restored later
269+
// PHP only supports $this inside anonymous functions since 5.4
270+
$minifier = $this;
271+
$callback = function ($match) use ($minifier) {
272+
$count = count($minifier->extracted);
273+
$placeholder = '/*'.$count.'*/';
274+
$minifier->extracted[$placeholder] = $match[0];
275+
276+
return $placeholder;
277+
};
278+
$this->registerPattern('/
279+
# optional newline
280+
\n?
281+
282+
# start comment
283+
\/\*
284+
285+
# comment content
286+
(?:
287+
# either starts with an !
288+
!
289+
|
290+
# or, after some number of characters which do not end the comment
291+
(?:(?!\*\/).)*?
292+
293+
# there is either a @license or @preserve tag
294+
@(?:license|preserve)
295+
)
296+
297+
# then match to the end of the comment
298+
.*?\*\/\n?
299+
300+
/ixs', $callback);
301+
302+
// Then strip all other comments
303+
$this->registerPattern('/\/\*.*?\*\//s', '');
304+
}
305+
263306
/**
264307
* We can't "just" run some regular expressions against JavaScript: it's a
265308
* complex language. E.g. having an occurrence of // xyz would be a comment,

‎lib/minify/readme_moodle.txt

+1-7
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,4 @@ mv path-converter-A.B.C/src/ /path/to/moodle/lib/minify/matthiasmullie-pathconve
1515

1616
3) Apply the following patches:
1717

18-
MDL-68191: https://github.com/matthiasmullie/minify/issues/317 is a bug that stops
19-
large sections of the CSS from being minimised, and also is a huge performance drain.
20-
We have applied the fix sent upstream because the performance win is so big.
21-
(E.g. one case I measured, with the bug was 40 seconds to minify CSS, with the fix was
22-
a few seconds. This is one of the reasons Behat runs in the browser are so slow.)
23-
Whenever this library is updated check if the fix is included and remove this note.
24-
NOTE: As of 2020/12/08, only the first commit was brought into Moodle
18+
N/A

‎lib/thirdpartylibs.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<location>minify/matthiasmullie-minify</location>
8383
<name>MatthiasMullie\Minify</name>
8484
<description>CSS &amp; JavaScript minifier, in PHP</description>
85-
<version>1.3.70</version>
85+
<version>1.3.71</version>
8686
<license>MIT</license>
8787
<repository>https://github.com/matthiasmullie/minify</repository>
8888
<customised/>

0 commit comments

Comments
 (0)
Please sign in to comment.