From aab221f2c315b1e33470779bee9762de3180a3bf Mon Sep 17 00:00:00 2001 From: Peter Dias Date: Wed, 13 Jan 2021 10:08:06 +0800 Subject: [PATCH 1/4] MDL-70291 core: Upgrade minify lib to 1.3.63 --- lib/minify/matthiasmullie-minify/src/CSS.php | 31 +-------------- .../matthiasmullie-minify/src/Minify.php | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/lib/minify/matthiasmullie-minify/src/CSS.php b/lib/minify/matthiasmullie-minify/src/CSS.php index a66dfe0353e..89fcf1bbb13 100644 --- a/lib/minify/matthiasmullie-minify/src/CSS.php +++ b/lib/minify/matthiasmullie-minify/src/CSS.php @@ -636,35 +636,7 @@ 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', ''); } @@ -736,7 +708,8 @@ class CSS extends Minify return $placeholder.$rest; }; - $this->registerPattern('/calc(\(.+?)(?=$|;|calc\()/', $callback); + $this->registerPattern('/calc(\(.+?)(?=$|;|}|calc\()/', $callback); + $this->registerPattern('/calc(\(.+?)(?=$|;|}|calc\()/m', $callback); } /** diff --git a/lib/minify/matthiasmullie-minify/src/Minify.php b/lib/minify/matthiasmullie-minify/src/Minify.php index e5fefe6f948..3f40bc1578c 100644 --- a/lib/minify/matthiasmullie-minify/src/Minify.php +++ b/lib/minify/matthiasmullie-minify/src/Minify.php @@ -99,6 +99,44 @@ abstract class Minify return $this; } + /** + * Add a file to be minified. + * + * @param string|string[] $data + * + * @return static + * + * @throws IOException + */ + public function addFile($data /* $data = null, ... */) + { + // bogus "usage" of parameter $data: scrutinizer warns this variable is + // not used (we're using func_get_args instead to support overloading), + // but it still needs to be defined because it makes no sense to have + // this function without argument :) + $args = array($data) + func_get_args(); + + // this method can be overloaded + foreach ($args as $path) { + if (is_array($path)) { + call_user_func_array(array($this, 'addFile'), $path); + continue; + } + + // redefine var + $path = (string) $path; + + // check if we can read the file + if (!$this->canImportFile($path)) { + throw new IOException('The file "'.$path.'" could not be opened for reading. Check if PHP has enough permissions.'); + } + + $this->add($path); + } + + return $this; + } + /** * Minify the data & (optionally) saves it to a file. * From c28728112f30d27507d71de0b0dbaf91c0cd7933 Mon Sep 17 00:00:00 2001 From: Peter Dias Date: Wed, 13 Jan 2021 10:19:54 +0800 Subject: [PATCH 2/4] MDL-70291 core: Upgrade pathconverter lib to 1.1.3 --- lib/minify/matthiasmullie-pathconverter/src/Converter.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/minify/matthiasmullie-pathconverter/src/Converter.php b/lib/minify/matthiasmullie-pathconverter/src/Converter.php index 519d3c84ff5..80cf269b94c 100644 --- a/lib/minify/matthiasmullie-pathconverter/src/Converter.php +++ b/lib/minify/matthiasmullie-pathconverter/src/Converter.php @@ -71,6 +71,14 @@ class Converter implements ConverterInterface // deal with different operating systems' directory structure $path = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '/'); + // remove leading current directory. + if (substr($path, 0, 2) === './') { + $path = substr($path, 2); + } + + // remove references to current directory in the path. + $path = str_replace('/./', '/', $path); + /* * Example: * /home/forkcms/frontend/cache/compiled_templates/../../core/layout/css/../images/img.gif From b21db6aa4331e535d07e5711381e1473e6246eb5 Mon Sep 17 00:00:00 2001 From: Peter Dias Date: Wed, 13 Jan 2021 10:20:15 +0800 Subject: [PATCH 3/4] MDL-70291 core: Add custom moodle patch to minify --- lib/minify/matthiasmullie-minify/src/CSS.php | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/minify/matthiasmullie-minify/src/CSS.php b/lib/minify/matthiasmullie-minify/src/CSS.php index 89fcf1bbb13..e00856f6003 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', ''); } From 2389cca8584bbe749bb9786b38a64fa19514721a Mon Sep 17 00:00:00 2001 From: Peter Dias Date: Mon, 7 Dec 2020 15:23:37 +0800 Subject: [PATCH 4/4] MDL-70291 core: Update lib readme, upgrade and xml files --- lib/minify/readme_moodle.txt | 11 +++++++---- lib/thirdpartylibs.xml | 4 ++-- lib/upgrade.txt | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/minify/readme_moodle.txt b/lib/minify/readme_moodle.txt index d03fa3d894c..5d2f45408d1 100644 --- a/lib/minify/readme_moodle.txt +++ b/lib/minify/readme_moodle.txt @@ -11,13 +11,16 @@ mv path-converter-1.1.0/src/ /path/to/moodle/lib/minify/matthiasmullie-pathconve 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. + NOTE: As of 2020/12/08, only the first commit was brought into Moodle + + +2020-12-07 - Peter Dias +----------------------- +* Removed php74 compliance step as it is now part of the library +* Updated minify to 1.3.63 and pathconverter to 1.1.3 \ No newline at end of file diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml index 768a7af3d57..3a717ed0603 100644 --- a/lib/thirdpartylibs.xml +++ b/lib/thirdpartylibs.xml @@ -60,14 +60,14 @@ minify/matthiasmullie-minify MatthiasMullie\Minify MIT - 1.3.61 + 1.3.63 minify/matthiasmullie-pathconverter MatthiasMullie\PathConverter MIT - 1.1.2 + 1.1.3 diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 499aedabe96..ee011818374 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -15,6 +15,7 @@ information provided here is intended especially for developers. * Behat timeout constants behat_base::TIMEOUT, EXTENDED_TIMEOUT, and REDUCED_TIMEOUT, which were deprecated in 3.7, have been removed. * \core_table\local\filter\filterset::JOINTYPE_DEFAULT is being changed from 1 (ANY) to 2 (ALL). Filterset implementations can override the default filterset join type by overriding \core_table\local\filter\filterset::get_join_type() instead. +* The minify lib has been upgraded to 1.3.63 and pathconvertor to 1.1.3 === 3.10 === * PHPUnit has been upgraded to 8.5. That comes with a few changes: