[TYPO3-core] RFC #6415: Bug: preg_replace error on php5.2 sometimes resulting in empty pages.

Jan-Erik Revsbech janerik at mocsystems.com
Sun Jan 20 21:49:38 CET 2008


This is an SVN patch request.

Type: Bugfix

Bugtracker references:
http://bugs.typo3.org/view.php?id=6415


Branches:
Trunk

Problem:
The function prefixLocalAnchorsWithScript in class.tslib_fe.php runs
preg_replace directly on $this->content. 
In php 5.2 all calls to preg_* functions will return an empty string (or
false) if it encounters an error (This is new in PHP 5.2). thus is a pages
consists of a lot of content with many anchor links, the
pcre.backtrack_limit or pcre.recursiion_limit will be reached, and the
result is a completely blank output in the frontend.

The error only occurs if the TypoScript option: config.prefixLocalAnchors is
set to all.

The original trigger for this bug, was that the regular expression:
'/(<(a|area).*?href=")(#[^"]*")/i' resulted in recursion_limit being reached
on one of my sites. The regular expression is not correct, and should in my
opinion be '/(<(a|area).+href=")(#[^"]*")/i'

Solution:
1: Change the regular expression to a non-faulty one
2: Introduce some error checking. Since php 5.2 a call to preg_last_error
will give some insight into the result of the last call to preg_ functions.
The patch here checks if there was an error, and if yes, then return the
unsubstitued content (in order to avoid empty pages) and  write an entry to
the syslog. 

Notes:
The patch requires php 5.2 to run.

Regards
Jan-Erik Revsbech
MOC Systems
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 6415.diff
Type: application/octet-stream
Size: 1296 bytes
Desc: not available
Url : http://lists.netfielders.de/pipermail/typo3-team-core/attachments/20080120/050d8e65/attachment.obj 


More information about the TYPO3-team-core mailing list