From 0c8dd6fd1b14d80bdfd7bfcb839844b851af333c Mon Sep 17 00:00:00 2001 From: Molkobain Date: Tue, 6 Nov 2018 17:35:17 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B0562=20Notifications:=20Add=20support=20f?= =?UTF-8?q?or=20placeholders=20in=20HTML=20hyperlinks=20(regular=20href,?= =?UTF-8?q?=20mailto,=20...)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/metamodel.class.php | 45 +++++++++++-------- test/core/MetaModelTest.php | 86 +++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 19 deletions(-) create mode 100644 test/core/MetaModelTest.php diff --git a/core/metamodel.class.php b/core/metamodel.class.php index aee4a756d..a67d4434a 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -6893,25 +6893,32 @@ abstract class MetaModel { // Expand the parameters for the object $sName = substr($sSearch, 0, $iPos); - if (preg_match_all('/\\$'.$sName.'-(>|>)([^\\$]+)\\$/', $sInput, $aMatches)) // Support both syntaxes: $this->xxx$ or $this->xxx$ for HTML compatibility - { - foreach($aMatches[2] as $idx => $sPlaceholderAttCode) - { - try - { - $sReplacement = $replace->GetForTemplate($sPlaceholderAttCode); - if ($sReplacement !== null) - { - $aReplacements[] = $sReplacement; - $aSearches[] = '$'.$sName.'-'.$aMatches[1][$idx].$sPlaceholderAttCode.'$'; - } - } - catch (Exception $e) - { - // No replacement will occur - } - } - } + $aRegExps = array( + '/(\\$)'.$sName.'-(>|>)([^\\$]+)\\$/', // Support both syntaxes: $this->xxx$ or $this->xxx$ for HTML compatibility + '/(%24)'.$sName.'-(>|>)([^%24]+)%24/', // Support for urlencoded in HTML attributes (%20this->xxx%20) + ); + foreach($aRegExps as $sRegExp) + { + if(preg_match_all($sRegExp, $sInput, $aMatches)) + { + foreach($aMatches[3] as $idx => $sPlaceholderAttCode) + { + try + { + $sReplacement = $replace->GetForTemplate($sPlaceholderAttCode); + if($sReplacement !== null) + { + $aReplacements[] = $sReplacement; + $aSearches[] = $aMatches[1][$idx] . $sName . '-' . $aMatches[2][$idx] . $sPlaceholderAttCode . $aMatches[1][$idx]; + } + } + catch(Exception $e) + { + // No replacement will occur + } + } + } + } } else { diff --git a/test/core/MetaModelTest.php b/test/core/MetaModelTest.php new file mode 100644 index 000000000..07e413f24 --- /dev/null +++ b/test/core/MetaModelTest.php @@ -0,0 +1,86 @@ +createObject( + 'UserRequest', + array( + 'org_id' => static::$iDefaultUserOrgId, + 'caller_id' => static::$iDefaultUserCallerId, + 'title' => static::$sDefaultUserRequestTitle, + 'description' => static::$sDefaultUserRequestDescription, + ) + ); + + $aParams['this->object()'] = $oUserRequest; + + $sGeneratedOutput = MetaModel::ApplyParams($sInput, $aParams); + + $this->assertEquals($sExpectedOutput, $sGeneratedOutput, "ApplyParams test returned $sGeneratedOutput"); + } + + public function ApplyParamsProvider() + { + $sTitle = static::$sDefaultUserRequestTitle; + + $aParams = array(); + + return array( + 'Object string attribute (text format)' => array( + 'Title: $this->title$', + $aParams, + 'Title: '.$sTitle, + ), + 'Object string attribute (html format)' => array( + 'Title:

$this->title$

', + $aParams, + 'Title:

'.$sTitle.'

', + ), + 'Object string attribute urlencoded (html format)' => array( + 'Title: Hyperlink', + $aParams, + 'Title: Hyperlink', + ), + ); + } +} \ No newline at end of file