From 9b11b2c833477bf1fa4e22b2def2b555c63b2af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.bernigaud@opensides.be> Date: Fri, 3 Jun 2016 08:48:58 +0200 Subject: [PATCH] Fixes #4840 Improving recursion dependency detection and behavior --- include/class_plugin.inc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/include/class_plugin.inc b/include/class_plugin.inc index 40df4900c..03690f9de 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -773,20 +773,30 @@ class plugin return $result; } - static function tpl_depends_of (&$cache, $depends, $key, $forbidden = NULL) + static function tpl_depends_of (&$cache, $depends, $key, $forbidden = array()) { if (isset($cache[$key])) { return $cache[$key]; } - if ($forbidden === NULL) { - $forbidden = $key; - } elseif ($forbidden == $key) { - die('Error : recursive dependency'); - } - $array = + + $forbidden[] = $key; + + $array = array_map( function ($a) use (&$cache, $depends, $forbidden) { + if (in_array($a, $forbidden)) { + msg_dialog::display( + _('Error'), + sprintf( + _('Recursive dependency in the template fields: "%1$s" cannot depend on "%2$s" as "%2$s" already depends on "%1$s"'), + $key, + $a + ), + ERROR_DIALOG + ); + return array(); + } $deps = plugin::tpl_depends_of ($cache, $depends, $a, $forbidden); if (($askmeKey = array_search('askme', $deps)) !== FALSE) { /* Do not flat special askme dependency */ -- GitLab