diff options
author | Stefan Giehl <stefan@matomo.org> | 2021-12-07 22:44:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-07 22:44:01 +0300 |
commit | 4f5cda954a6b64677f9b48223a91e0ec8785e055 (patch) | |
tree | f1ff518dc59ac88c2e30448dee56fe1b7ab656a3 | |
parent | cd2cd0c041e25817a7887d7dcc7dfc6d232b9788 (diff) |
Fix 'Call to undefined function Piwik\piwik_fix_lbrace()' (#18461)
-rw-r--r-- | core/Common.php | 32 | ||||
-rw-r--r-- | core/Twig.php | 21 | ||||
-rw-r--r-- | plugins/Diagnostics/Diagnostic/DiagnosticResult.php | 3 |
3 files changed, 34 insertions, 22 deletions
diff --git a/core/Common.php b/core/Common.php index 90ceda1d4f..08751d5cbe 100644 --- a/core/Common.php +++ b/core/Common.php @@ -577,6 +577,38 @@ class Common return $value; } + /** + * Replaces lbrace with an encoded entity to prevent angular from parsing the content + * + * @deprecated Will be removed, once the vue js migration is done + * + * @param $string + * @return array|string|string[]|null + */ + public static function fixLbrace($string) + { + $chars = array('{', '{', '{', '{', '{', '{'); + + static $search; + static $replace; + + if (!isset($search)) { + $search = array_map(function ($val) { return $val . $val; }, $chars); + } + if (!isset($replace)) { + $replace = array_map(function ($val) { return $val . '⁣' . $val; }, $chars); + } + + $replacedString = is_null($string) ? $string : str_replace($search, $replace, $string); + + // try to replace characters until there are no changes + if ($string !== $replacedString) { + return self::fixLbrace($replacedString); + } + + return $string; + } + /* * Generating unique strings */ diff --git a/core/Twig.php b/core/Twig.php index e5b5e24958..abf3549af2 100644 --- a/core/Twig.php +++ b/core/Twig.php @@ -42,26 +42,7 @@ function piwik_format_number($string, $minFractionDigits, $maxFractionDigits) function piwik_fix_lbrace($string) { - $chars = array('{', '{', '{', '{', '{', '{'); - - static $search; - static $replace; - - if (!isset($search)) { - $search = array_map(function ($val) { return $val . $val; }, $chars); - } - if (!isset($replace)) { - $replace = array_map(function ($val) { return $val . '⁣' . $val; }, $chars); - } - - $replacedString = is_null($string) ? $string : str_replace($search, $replace, $string); - - // try to replace characters until there are no changes - if ($string !== $replacedString) { - return piwik_fix_lbrace($replacedString); - } - - return $string; + return Common::fixLbrace($string); } function piwik_escape_filter(Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false) { diff --git a/plugins/Diagnostics/Diagnostic/DiagnosticResult.php b/plugins/Diagnostics/Diagnostic/DiagnosticResult.php index a66a4a3245..466396ec56 100644 --- a/plugins/Diagnostics/Diagnostic/DiagnosticResult.php +++ b/plugins/Diagnostics/Diagnostic/DiagnosticResult.php @@ -9,7 +9,6 @@ namespace Piwik\Plugins\Diagnostics\Diagnostic; use Piwik\Common; -use function Piwik\piwik_fix_lbrace; /** * The result of a diagnostic. @@ -71,7 +70,7 @@ class DiagnosticResult } if ($escapeComment) { - $comment = piwik_fix_lbrace(Common::sanitizeInputValue($comment)); + $comment = Common::fixLbrace(Common::sanitizeInputValue($comment)); } return self::singleResult($label, self::STATUS_INFORMATIONAL, $comment); |