Skip to content

Commit

Permalink
[BUGFIX] Prevent different constants marker in TS parsing
Browse files Browse the repository at this point in the history
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/51867
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
  • Loading branch information
IchHabRecht committed Feb 26, 2017
1 parent 0af1c88 commit ac9baec
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@ class ExtendedTemplateService extends TemplateService
*/
public $clearList_setup_temp;

/**
* @var string
*/
protected $Cmarker = '';

/**
* @var string
*/
Expand Down Expand Up @@ -281,7 +276,6 @@ class ExtendedTemplateService extends TemplateService
*/
public function substituteConstants($all)
{
$this->Cmarker = substr(md5(uniqid('', true)), 0, 6);
return preg_replace_callback('/\\{\\$(.[^}]+)\\}/', [$this, 'substituteConstantsCallBack'], $all);
}

Expand All @@ -294,12 +288,13 @@ public function substituteConstants($all)
*/
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];
Expand All @@ -311,7 +306,7 @@ public function substituteConstantsCallBack($matches)
}

/**
* Subsitute markers
* Substitute markers
*
* @param string $all
* @return string
Expand All @@ -321,10 +316,10 @@ public function substituteCMarkers($all)
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:
Expand Down Expand Up @@ -804,9 +799,10 @@ public function ext_fixed_lgd($string, $chars)
{
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);
}
Expand Down

0 comments on commit ac9baec

Please sign in to comment.