From 1dca8d17aad8703837ccb481dc416ea8c034ba73 Mon Sep 17 00:00:00 2001 From: Nicole Cordes <typo3@cordes.co> Date: Tue, 4 Oct 2016 15:21:57 +0200 Subject: [PATCH] [BUGFIX] Prevent different constants marker in TS parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently each time the TypoScript is parsed a new marker for constants, which are replaces by their value, is generated. This prevents conditions with replaced constants to be displayed as active. This patch ensures markers are generated by constants values and therefore stay the same in different requests. Resolves: #78142 Related: #72413 Releases: master, 7.6 Change-Id: I4eea83908927ac48930abdd731e7412c04e529c1 Reviewed-on: https://review.typo3.org/50088 Tested-by: TYPO3com <no-reply@typo3.com> Tested-by: Jasmina Ließmann <code@frauliessmann.de> Reviewed-by: Markus Klein <markus.klein@typo3.org> Tested-by: Markus Klein <markus.klein@typo3.org> Reviewed-by: Nicole Cordes <typo3@cordes.co> Tested-by: Nicole Cordes <typo3@cordes.co> --- .../TypoScript/ExtendedTemplateService.php | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php b/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php index e8b410595e87..806b3f4d8498 100644 --- a/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php +++ b/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php @@ -209,11 +209,6 @@ class ExtendedTemplateService extends TemplateService */ public $clearList_setup_temp; - /** - * @var string - */ - protected $Cmarker = ''; - /** * @var string */ @@ -277,7 +272,6 @@ class ExtendedTemplateService extends TemplateService */ public function substituteConstants($all) { - $this->Cmarker = substr(md5(uniqid('', true)), 0, 6); return preg_replace_callback('/\\{\\$(.[^}]+)\\}/', [$this, 'substituteConstantsCallBack'], $all); } @@ -290,12 +284,13 @@ class ExtendedTemplateService extends TemplateService */ public function substituteConstantsCallBack($matches) { + $marker = substr(md5($matches[0]), 0, 6); switch ($this->constantMode) { case 'const': - $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? '##' . $this->Cmarker . '_B##' . $matches[0] . '##' . $this->Cmarker . '_E##' : $matches[0]; + $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? '##' . $marker . '_B##' . $matches[0] . '##' . $marker . '_E##' : $matches[0]; break; case 'subst': - $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? '##' . $this->Cmarker . '_B##' . $this->flatSetup[$matches[1]] . '##' . $this->Cmarker . '_E##' : $matches[0]; + $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? '##' . $marker . '_B##' . $this->flatSetup[$matches[1]] . '##' . $marker . '_E##' : $matches[0]; break; case 'untouched': $ret_val = $matches[0]; @@ -307,7 +302,7 @@ class ExtendedTemplateService extends TemplateService } /** - * Subsitute markers + * Substitute markers * * @param string $all * @return string @@ -317,10 +312,10 @@ class ExtendedTemplateService extends TemplateService switch ($this->constantMode) { case 'const': case 'subst': - $all = str_replace( - ['##' . $this->Cmarker . '_B##', '##' . $this->Cmarker . '_E##'], - ['<strong style="color: green;">', '</strong>'], - $all + $all = preg_replace( + '/##[a-z0-9]{6}_B##((?:(?!##[a-z0-9]{6}_E##).)+)##[a-z0-9]{6}_E##/', + '<strong style="color: green;">$1</strong>', + $all ); break; default: @@ -781,9 +776,10 @@ class ExtendedTemplateService extends TemplateService { if ($chars >= 4) { if (strlen($string) > $chars) { - if (strlen($string) > 24 && substr($string, 0, 12) === '##' . $this->Cmarker . '_B##') { - return '##' . $this->Cmarker . '_B##' . GeneralUtility::fixed_lgd_cs(substr($string, 12, -12), ($chars - 3)) - . '##' . $this->Cmarker . '_E##'; + if (strlen($string) > 24 && preg_match('/^##[a-z0-9]{6}_B##$/', substr($string, 0, 12))) { + $string = GeneralUtility::fixed_lgd_cs(substr($string, 12, -12), ($chars - 3)); + $marker = substr(md5($string), 0, 6); + return '##' . $marker . '_B##' . $string . '##' . $marker . '_E##'; } else { return GeneralUtility::fixed_lgd_cs($string, $chars - 3); } -- GitLab