diff --git a/typo3/sysext/core/Documentation/Changelog/master/Important-72050-EncapsLinesDoesNotRenderDuplicateParagraphs.rst b/typo3/sysext/core/Documentation/Changelog/master/Important-72050-EncapsLinesDoesNotRenderDuplicateParagraphs.rst new file mode 100644 index 0000000000000000000000000000000000000000..03d5e2baa14326f7116632b627ec700e188c576b --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Important-72050-EncapsLinesDoesNotRenderDuplicateParagraphs.rst @@ -0,0 +1,22 @@ +.. include:: ../../Includes.txt + +============================================================================ +Important: #72050 - encapsLines does not render duplicate paragraphs anymore +============================================================================ + +See :issue:`72050` + +Description +=========== + +In the past the +`_encapsLines` TypoScript function +https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Encapslines/Index.html +rendered two paragraphs for one empty trailing line-break in the content. + +This behaviour is now fixed. + +Your Frontend appearance might change if you had multiple empty trailing paragraphs +in your RTE content. The last paragraph is not rendered twice in the Frontend anymore. + +.. index:: Frontend, RTE, TypoScript diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php index 8262ea18a9e6cb2dd0384189cd331bd0a3ebd825..875f0ea6fde3330a1b97baa326f993fc772d7a4b 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php +++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php @@ -4881,15 +4881,23 @@ class ContentObjectRenderer */ public function encaps_lineSplit($theValue, $conf) { + if ((string)$theValue === '') { + return ''; + } $lParts = explode(LF, $theValue); + + // When the last element is an empty linebreak we need to remove it, otherwise we will have a duplicate empty line. + $lastPartIndex = count($lParts) - 1; + if ($lParts[$lastPartIndex] === '' && trim($lParts[$lastPartIndex - 1], CR) === '') { + array_pop($lParts); + } + $encapTags = GeneralUtility::trimExplode(',', strtolower($conf['encapsTagList']), true); $nonWrappedTag = $conf['nonWrappedTag']; $defaultAlign = isset($conf['defaultAlign.']) ? trim($this->stdWrap($conf['defaultAlign'], $conf['defaultAlign.'])) : trim($conf['defaultAlign']); - if ((string)$theValue === '') { - return ''; - } + $str_content = ''; foreach ($lParts as $k => $l) { $sameBeginEnd = 0; diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php index 297c4622fc575871002659cfca3c79454261ebe9..631a9be7e3248e5948a66b826d91ecb9e5087be8 100644 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php @@ -2584,6 +2584,26 @@ class ContentObjectRendererTest extends UnitTestCase $this->getLibParseFunc_RTE(), '<p class="bodytext">Text with <a href="http://example.com/foo/">external link</a></p>', ], + 'Empty lines are not duplicated' => [ + LF, + $this->getLibParseFunc_RTE(), + '<p class="bodytext"> </p>', + ], + 'Multiple empty lines with no text' => [ + LF . LF . LF, + $this->getLibParseFunc_RTE(), + '<p class="bodytext"> </p>' . LF . '<p class="bodytext"> </p>' . LF . '<p class="bodytext"> </p>', + ], + 'Empty lines are not duplicated at the end of content' => [ + 'test' . LF . LF, + $this->getLibParseFunc_RTE(), + '<p class="bodytext">test</p>' . LF . '<p class="bodytext"> </p>', + ], + 'Empty lines are not trimmed' => [ + LF . 'test' . LF, + $this->getLibParseFunc_RTE(), + '<p class="bodytext"> </p>' . LF . '<p class="bodytext">test</p>' . LF . '<p class="bodytext"> </p>', + ], ]; }