[TYPO3-core] RFC #7984: Bug: stdWrap.crop now closes opened tags and counts chars correctly

Martin Kutschker Martin.Kutschker at n0spam-blackbox.net
Fri Apr 4 13:42:30 CEST 2008


Jochen Rau schrieb:
> This is an SVN patch request.
> 
> Type: Bugfix
> 
> Bugtracker references: http://bugs.typo3.org/view.php?id=7984
> 
> Branches: TYPO3_4-1, TYPO3_4-2 and trunk
> 
> Problems:
> 1) After stdWrap.crop has cropped text opened tags are not closed. This 
> leads to unvalid HTML-code and strange FE-rendering.
> 2) stdWrap.crop counts chars of tags in text. This leads to shorter 
> visible cropped text in FE.
> 3) stdWrap.crop counts chars of HTML-entities instead of the represented 
> char (see 2)).

This is indeed a problem, but you cannot simply change the behaviour of 
crop as it might me be used on plain text. So this will have to be 
stdWrap.cropHTML (or stdWrap.cropXML) which makes at new feature. Which 
makes it TYPO3_4-2 only, that is if you get the ok from the release 
managers. RC1 is already out!

> Solution:
> In the proposed solution the content is splitted into an array. This 
> array is parsed and each openen tag gets closed. Tags are not counted 
> and HTML-entities are decoded before strlen is determined.

Not terribly thrilling I'm afraid. It's simple enough to use either 
strpos() or preg_match() * to walk through the html without having to split 
the entire content.

A more serious problem is that you use html_entity_decode() which supports 
only a subset of the charset TYPO3 supports.

I also do not understand why you have a list of tags to split on. It's much 
easier and forward compatible to work on all tags that come along.

> Notes:
> In the proposed solution cropping at the last white space (to avoid 
> broken words) can not "slide" over a tag.

Good. Is this worth being configurable?

Thanx for trying, but there is IMHO much room for improvement.

Masi

* eg
preg_match('/<([^ >]+)([^>]*)>/', $html, $match, PREG_OFFSET_CAPTURE)



More information about the TYPO3-team-core mailing list