From b4ed28a7d23e3b015dad14d4f8fdbfb019f9f2a4 Mon Sep 17 00:00:00 2001 From: Alexander Stehlik <alexander.stehlik@gmail.com> Date: Sat, 3 Dec 2016 17:44:13 +0100 Subject: [PATCH] [BUGFIX] Prevent duplicate empty lines for encapsLines When the last line in the text passed to encaps_lineSplit() is empty a possible duplicate empty line is removed. Releases: master Resolves: #72050 Change-Id: I358ae5e1e6e9731d4649add7951c93e62df3bb7e Reviewed-on: https://review.typo3.org/45111 Reviewed-by: Manuel Glauser <mail@manuelglauser.ch> Tested-by: Manuel Glauser <mail@manuelglauser.ch> Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Jan Helke <typo3@helke.de> Tested-by: Jan Helke <typo3@helke.de> --- ...sLinesDoesNotRenderDuplicateParagraphs.rst | 22 +++++++++++++++++++ .../ContentObject/ContentObjectRenderer.php | 14 +++++++++--- .../ContentObjectRendererTest.php | 20 +++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Important-72050-EncapsLinesDoesNotRenderDuplicateParagraphs.rst 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 000000000000..03d5e2baa143 --- /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 8262ea18a9e6..875f0ea6fde3 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 297c4622fc57..631a9be7e324 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>', + ], ]; } -- GitLab