From b014bb998500445cc51fbc461fb09eeea2013f03 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Tue, 9 Aug 2022 19:20:10 +0800 Subject: [PATCH] MDL-75388 lib: Update mustache to 2.14.1 MDL-67114 and MDL-73586 local changes removed as they are now available upstream. --- lib/mustache/readme_moodle.txt | 6 ------ lib/mustache/src/Mustache/Cache.php | 7 +++++++ lib/mustache/src/Mustache/Cache/AbstractCache.php | 2 +- lib/mustache/src/Mustache/Compiler.php | 13 +++++-------- lib/mustache/src/Mustache/Engine.php | 4 ++-- .../src/Mustache/Source/FilesystemSource.php | 4 ++-- lib/mustache/src/Mustache/Tokenizer.php | 6 +++--- lib/thirdpartylibs.xml | 2 +- 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/mustache/readme_moodle.txt b/lib/mustache/readme_moodle.txt index 75b29f4ae75..5b70cddd3ba 100644 --- a/lib/mustache/readme_moodle.txt +++ b/lib/mustache/readme_moodle.txt @@ -17,9 +17,3 @@ Local changes: Note: All this changes need to be reviewed on every upgrade and, if they have been already applied upstream for the release being used, can be removed from the list. If still not available upstream, they will need to be re-applied. - -- MDL-67114: PHP 7.4 compatibility. Array operations on scalar value. - This corresponds to upstream https://github.com/bobthecow/mustache.php/pull/352 -- MDL-73586: PHP 8.0 compatibility. Removed 'mbstring.func_overload' init setting. - This corresponds to upstream commit https://github.com/bobthecow/mustache.php/commit/e7165a33b282ab4d20b3863825caadb46313d62b - that is availbale for the library versions 2.14.1 and up diff --git a/lib/mustache/src/Mustache/Cache.php b/lib/mustache/src/Mustache/Cache.php index 3b5b3f1bf47..3292efac7de 100644 --- a/lib/mustache/src/Mustache/Cache.php +++ b/lib/mustache/src/Mustache/Cache.php @@ -33,4 +33,11 @@ interface Mustache_Cache * @param string $value */ public function cache($key, $value); + + /** + * Set a logger instance. + * + * @param Mustache_Logger|Psr\Log\LoggerInterface $logger + */ + public function setLogger($logger = null); } diff --git a/lib/mustache/src/Mustache/Cache/AbstractCache.php b/lib/mustache/src/Mustache/Cache/AbstractCache.php index 365eafac6a0..281038fa67f 100644 --- a/lib/mustache/src/Mustache/Cache/AbstractCache.php +++ b/lib/mustache/src/Mustache/Cache/AbstractCache.php @@ -47,7 +47,7 @@ abstract class Mustache_Cache_AbstractCache implements Mustache_Cache /** * Add a log record if logging is enabled. * - * @param int $level The logging level + * @param string $level The logging level * @param string $message The log message * @param array $context The log context */ diff --git a/lib/mustache/src/Mustache/Compiler.php b/lib/mustache/src/Mustache/Compiler.php index 610369ed6e9..93a295ae5d2 100644 --- a/lib/mustache/src/Mustache/Compiler.php +++ b/lib/mustache/src/Mustache/Compiler.php @@ -286,7 +286,6 @@ class Mustache_Compiler private function blockArg($nodes, $id, $start, $end, $otag, $ctag, $level) { $key = $this->block($nodes); - $keystr = var_export($key, true); $id = var_export($id, true); return sprintf($this->prepare(self::BLOCK_ARG, $level), $id, $key); @@ -321,7 +320,6 @@ class Mustache_Compiler } const SECTION_CALL = ' - // %s section $value = $context->%s(%s);%s $buffer .= $this->section%s($context, $indent, $value); '; @@ -333,12 +331,12 @@ class Mustache_Compiler if (%s) { $source = %s; - $result = call_user_func($value, $source, %s); + $result = (string) call_user_func($value, $source, %s); if (strpos($result, \'{{\') === false) { $buffer .= $result; } else { $buffer .= $this->mustache - ->loadLambda((string) $result%s) + ->loadLambda($result%s) ->renderInternal($context); } } elseif (!empty($value)) { @@ -392,11 +390,10 @@ class Mustache_Compiler $id = var_export($id, true); $filters = $this->getFilters($filters, $level); - return sprintf($this->prepare(self::SECTION_CALL, $level), $id, $method, $id, $filters, $key); + return sprintf($this->prepare(self::SECTION_CALL, $level), $method, $id, $filters, $key); } const INVERTED_SECTION = ' - // %s inverted section $value = $context->%s(%s);%s if (empty($value)) { %s @@ -419,7 +416,7 @@ class Mustache_Compiler $id = var_export($id, true); $filters = $this->getFilters($filters, $level); - return sprintf($this->prepare(self::INVERTED_SECTION, $level), $id, $method, $id, $filters, $this->walk($nodes, $level)); + return sprintf($this->prepare(self::INVERTED_SECTION, $level), $method, $id, $filters, $this->walk($nodes, $level)); } const PARTIAL_INDENT = ', $indent . %s'; @@ -507,7 +504,7 @@ class Mustache_Compiler const VARIABLE = ' $value = $this->resolveValue($context->%s(%s), $context);%s - $buffer .= %s%s; + $buffer .= %s($value === null ? \'\' : %s); '; /** diff --git a/lib/mustache/src/Mustache/Engine.php b/lib/mustache/src/Mustache/Engine.php index fe99799e058..5e96e4118c0 100644 --- a/lib/mustache/src/Mustache/Engine.php +++ b/lib/mustache/src/Mustache/Engine.php @@ -23,8 +23,8 @@ */ class Mustache_Engine { - const VERSION = '2.13.0'; - const SPEC_VERSION = '1.1.2'; + const VERSION = '2.14.0'; + const SPEC_VERSION = '1.2.2'; const PRAGMA_FILTERS = 'FILTERS'; const PRAGMA_BLOCKS = 'BLOCKS'; diff --git a/lib/mustache/src/Mustache/Source/FilesystemSource.php b/lib/mustache/src/Mustache/Source/FilesystemSource.php index 1284ac72c9d..270f584e490 100644 --- a/lib/mustache/src/Mustache/Source/FilesystemSource.php +++ b/lib/mustache/src/Mustache/Source/FilesystemSource.php @@ -38,7 +38,7 @@ class Mustache_Source_FilesystemSource implements Mustache_Source /** * Get the Source key (used to generate the compiled class name). * - * @throws RuntimeException when a source file cannot be read + * @throws Mustache_Exception_RuntimeException when a source file cannot be read * * @return string */ @@ -54,7 +54,7 @@ class Mustache_Source_FilesystemSource implements Mustache_Source } if ($this->stat === false) { - throw new RuntimeException(sprintf('Failed to read source file "%s".', $this->fileName)); + throw new Mustache_Exception_RuntimeException(sprintf('Failed to read source file "%s".', $this->fileName)); } foreach ($this->statProps as $prop) { diff --git a/lib/mustache/src/Mustache/Tokenizer.php b/lib/mustache/src/Mustache/Tokenizer.php index 71871226a34..2a172c34864 100644 --- a/lib/mustache/src/Mustache/Tokenizer.php +++ b/lib/mustache/src/Mustache/Tokenizer.php @@ -88,11 +88,11 @@ class Mustache_Tokenizer * @throws Mustache_Exception_InvalidArgumentException when $delimiters string is invalid * * @param string $text Mustache template source to tokenize - * @param string $delimiters Optionally, pass initial opening and closing delimiters (default: null) + * @param string $delimiters Optionally, pass initial opening and closing delimiters (default: empty string) * * @return array Set of Mustache tokens */ - public function scan($text, $delimiters = null) + public function scan($text, $delimiters = '') { // Setting mbstring.func_overload makes things *really* slow. // Let's do everyone a favor and scan this string as ASCII instead. @@ -112,7 +112,7 @@ class Mustache_Tokenizer $this->reset(); - if ($delimiters = trim($delimiters)) { + if (is_string($delimiters) && $delimiters = trim($delimiters)) { $this->setDelimiters($delimiters); } diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml index 4ac1df48dfa..47118aed1ce 100644 --- a/lib/thirdpartylibs.xml +++ b/lib/thirdpartylibs.xml @@ -308,7 +308,7 @@ All rights reserved. mustache Mustache PHP library for displaying mustache templates. - 2.13.0 + 2.14.1 MIT https://github.com/bobthecow/mustache.php