diff --git a/tests/typo3/sysext/cms/tslib/class.tslib_contentTest.php b/tests/typo3/sysext/cms/tslib/class.tslib_contentTest.php index 7f9ee15cc8455eb47def4fce4a52e18f6751cbc2..a3ce27d2fab8d6bdb9404b23fb6f704bd905c19e 100644 --- a/tests/typo3/sysext/cms/tslib/class.tslib_contentTest.php +++ b/tests/typo3/sysext/cms/tslib/class.tslib_contentTest.php @@ -422,9 +422,15 @@ class tslib_contentTest extends tx_phpunit_testcase { $charset . ' plain text; -58|...' => array( '-58|...', $plainText, '...h' . chr(248) . 'j implemented the original version of the crop function.', $charset ), + $charset . ' plain text; 4|...|1' => array( + '4|...|1', $plainText, 'Kasp...', $charset + ), $charset . ' plain text; 20|...|1' => array( '20|...|1', $plainText, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...', $charset ), + $charset . ' plain text; -5|...|1' => array( + '-5|...|1', $plainText, '...tion.', $charset + ), $charset . ' plain text; -49|...|1' => array( '-49|...|1', $plainText, '...the original version of the crop function.', $charset ), @@ -446,6 +452,9 @@ class tslib_contentTest extends tx_phpunit_testcase { $charset . ' text with markup; -58|...' => array( '-58|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">...h' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.', $charset ), + $charset . ' text with markup 4|...|1' => array( + '4|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasp...</a></strong>', $charset + ), $charset . ' text with markup; 11|...|1' => array( '11|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>', $charset ), @@ -494,6 +503,9 @@ class tslib_contentTest extends tx_phpunit_testcase { $charset . ' text with entities -59|...' => array( '-59|...', $textWithEntities, '...høj implemented the; original version of the crop function.', $charset ), + $charset . ' text with entities 4|...|1' => array( + '4|...|1', $textWithEntities, 'Kasp...', $charset + ), $charset . ' text with entities 9|...|1' => array( '9|...|1', $textWithEntities, 'Kasper...', $charset ), diff --git a/typo3/sysext/cms/tslib/class.tslib_content.php b/typo3/sysext/cms/tslib/class.tslib_content.php index 23d1e018ebb67c62c660129b41797132dca59c9d..ecf3a787904d59158ab04f77e68bd1d015129728 100644 --- a/typo3/sysext/cms/tslib/class.tslib_content.php +++ b/typo3/sysext/cms/tslib/class.tslib_content.php @@ -3681,17 +3681,29 @@ class tslib_cObj { $cropPosition = $absChars - $strLen; // The snippet "&[^&\s;]{2,8};" in the RegEx below represents entities. $patternMatchEntityAsSingleChar = '(&[^&\s;]{2,8};|.)'; - if ($crop2space) { - $cropRegEx = $chars < 0 - ? '#(?<=\s)' . $patternMatchEntityAsSingleChar . '{0,' . $cropPosition . '}$#ui' - : '#^' . $patternMatchEntityAsSingleChar . '{0,' . $cropPosition . '}(?=\s)#ui'; + + $cropRegEx = $chars < 0 + ? '#' . $patternMatchEntityAsSingleChar . '{0,' . ($cropPosition + 1) . '}$#ui' + : '#^' . $patternMatchEntityAsSingleChar . '{0,' . ($cropPosition + 1) . '}#ui'; + if (preg_match($cropRegEx, $tempContent, $croppedMatch)) { + $tempContentPlusOneCharacter = $croppedMatch[0]; } else { - $cropRegEx = $chars < 0 - ? '#' . $patternMatchEntityAsSingleChar . '{0,' . $cropPosition . '}$#ui' - : '#^' . $patternMatchEntityAsSingleChar . '{0,' . $cropPosition . '}#ui'; + $tempContentPlusOneCharacter = FALSE; } + + $cropRegEx = $chars < 0 + ? '#' . $patternMatchEntityAsSingleChar . '{0,' . $cropPosition . '}$#ui' + : '#^' . $patternMatchEntityAsSingleChar . '{0,' . $cropPosition . '}#ui'; if (preg_match($cropRegEx, $tempContent, $croppedMatch)) { $tempContent = $croppedMatch[0]; + if (($crop2space) && ($tempContentPlusOneCharacter !== FALSE)) { + $cropRegEx = $chars < 0 + ? '#(?<=\s)' . $patternMatchEntityAsSingleChar . '{0,' . $cropPosition . '}$#ui' + : '#^' . $patternMatchEntityAsSingleChar . '{0,' . $cropPosition . '}(?=\s)#ui'; + if (preg_match($cropRegEx, $tempContentPlusOneCharacter, $croppedMatch)) { + $tempContent = $croppedMatch[0]; + } + } } $splittedContent[$offset] = $GLOBALS['TSFE']->csConvObj->utf8_decode($tempContent, $GLOBALS['TSFE']->renderCharset); break;