diff --git a/lib/minify/matthiasmullie-minify/src/CSS.php b/lib/minify/matthiasmullie-minify/src/CSS.php index a9a70a0460a..a66dfe0353e 100644 --- a/lib/minify/matthiasmullie-minify/src/CSS.php +++ b/lib/minify/matthiasmullie-minify/src/CSS.php @@ -636,7 +636,35 @@ class CSS extends Minify 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', ''); } diff --git a/lib/minify/readme_moodle.txt b/lib/minify/readme_moodle.txt index 9593ad066d5..d03fa3d894c 100644 --- a/lib/minify/readme_moodle.txt +++ b/lib/minify/readme_moodle.txt @@ -14,3 +14,10 @@ Local changes applied: MDL-67115: php 74 compliance - implode() params order. Note this has been fixed upstream by https://github.com/matthiasmullie/minify/pull/300 so, whenever this library is updated check if the fix is included and remove this note. + +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.