N°2889 - MetaModel::ApplyParams now support placeholders with an arrow for non-object value (eg. $foo->bar$)

This commit is contained in:
Molkobain
2023-02-17 10:56:43 +01:00
parent 788a88fdc6
commit 0701f92143
2 changed files with 43 additions and 12 deletions

View File

@@ -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(

View File

@@ -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: <a href="http://foo.bar/%24foo-&gt;bar%24">Hyperlink</a>',
$aParams,
'Result: <a href="http://foo.bar/I am bar">Hyperlink</a>',
],
'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: <p>$this-&gt;title$</p>',
$aParams,
'Title: <p>'.$sTitle.'</p>',
),
'Object string attribute urlencoded (html format)' => array(
],
'Placeholder for an object string attribute url-encoded (html format)' => [
'Title: <a href="http://foo.bar/%24this-&gt;title%24">Hyperlink</a>',
$aParams,
'Title: <a href="http://foo.bar/'.$sTitle.'">Hyperlink</a>',
),
);
],
];
}
/**