From 0701f921437256e99fa0c83d01edc2ef72110de8 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Fri, 17 Feb 2023 10:56:43 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B02889=20-=20MetaModel::ApplyParams=20now?= =?UTF-8?q?=20support=20placeholders=20with=20an=20arrow=20for=20non-objec?= =?UTF-8?q?t=20value=20(eg.=20$foo->bar$)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/metamodel.class.php | 14 +++++-- .../unitary-tests/core/MetaModelTest.php | 41 +++++++++++++++---- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/core/metamodel.class.php b/core/metamodel.class.php index 147b3160d..759734bfc 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -7382,15 +7382,23 @@ abstract class MetaModel } } else { $aRegExps = array( - '/(\$)'.$sSearch.'\$/', // Support for regular placeholders (eg. $APP_URL$) - '/(%24)'.$sSearch.'%24/', // Support for urlencoded in HTML attributes (eg. %24APP_URL%24) + '/(\$)'.$sSearch.'\$/', // Regular placeholders (eg. $APP_URL$) or placeholders with an arrow in plain text (eg. $foo->bar$) + '/(%24)'.$sSearch.'%24/', // Regular placeholders url-encoded in HTML attributes (eg. %24APP_URL%24) + + '/(\$)'.utils::EscapeHtml($sSearch).'\$/', // Placeholders with an arrow in HTML (eg. $foo->bar$) + '/(%24)'.utils::EscapeHtml($sSearch).'%24/', // Placeholders with an arrow url-encoded in HTML attributes (eg. %24->bar%24) ); foreach ($aRegExps as $sRegExp) { if (preg_match_all($sRegExp, $sInput, $aMatches)) { foreach ($aMatches[1] as $idx => $sDelimiter) { try { - $aReplacements[] = (string)$replace; + // Regular or plain text + $aReplacements[] = (string) $replace; $aSearches[] = $aMatches[1][$idx].$sSearch.$aMatches[1][$idx]; + + // With an arrow in HTML + $aReplacements[] = (string) $replace; + $aSearches[] = $aMatches[1][$idx].utils::EscapeHtml($sSearch).$aMatches[1][$idx]; } catch (Exception $e) { IssueLog::Debug( diff --git a/tests/php-unit-tests/unitary-tests/core/MetaModelTest.php b/tests/php-unit-tests/unitary-tests/core/MetaModelTest.php index 4e4b0d961..51a97c906 100644 --- a/tests/php-unit-tests/unitary-tests/core/MetaModelTest.php +++ b/tests/php-unit-tests/unitary-tests/core/MetaModelTest.php @@ -64,25 +64,48 @@ class MetaModelTest extends ItopDataTestCase { $sTitle = static::$sDefaultUserRequestTitle; - $aParams = array(); + $aParams = [ + 'simple' => 'I am simple', + 'foo->bar' => 'I am bar', // N°2889 - Placeholder with an arrow that is not an object + ]; - return array( - 'Object string attribute (text format)' => array( + return [ + 'Simple placeholder' => [ + 'Result: $simple$', + $aParams, + 'Result: I am simple', + ], + 'Placeholder with an arrow but that is not an object (text format)' => [ + 'Result: $foo->bar$', + $aParams, + 'Result: I am bar', + ], + 'Placeholder with an arrow but that is not an object (html format)' => [ + 'Result: $foo->bar$', + $aParams, + 'Result: I am bar', + ], + 'Placeholder with an arrow url-encoded but that is not an object (html format)' => [ + 'Result: Hyperlink', + $aParams, + 'Result: Hyperlink', + ], + 'Placeholder for an object string attribute (text format)' => [ 'Title: $this->title$', $aParams, 'Title: '.$sTitle, - ), - 'Object string attribute (html format)' => array( + ], + 'Placeholder for an object string attribute (html format)' => [ 'Title:

$this->title$

', $aParams, 'Title:

'.$sTitle.'

', - ), - 'Object string attribute urlencoded (html format)' => array( + ], + 'Placeholder for an object string attribute url-encoded (html format)' => [ 'Title: Hyperlink', $aParams, 'Title: Hyperlink', - ), - ); + ], + ]; } /**