Ben Ward

"PHP4" bug in b2Evolution

.

Some regular visitors might have found a bug in the blog last week that meant you couldn’t access the “Comments” page for my entry on PHP4 XML parsers. After some debuggering, I’ve found the culprit in b2Evo 0.9.0.10’s source (not sure if it is present in 0.9.0.11).

The problem is caused by the presence of “php4” at the beginning of the permalink for the post. b2Evo also allows a syntax of “p<pagenumber>” to access posts. It was incorrectly catching the “p4” part of “php4” and trying to load a post number 4 that doesn’t appear to exist.

The problem is solved by editing line 115 of /b2evocore/_blog_main.php and changing it to read:

if( preg_match( "/^p([0-9]+)$/", $path_elements[$i], $req_post ) )

Although I’ve swapped to using the Perl-compatible regex function (which I just prefer) the critical change is the regular expression which goes from:

"p([0-9]+)"

to
"/^p([0-9]+)$/"

This adds in characters to mark the beginning and end of the string, so no false matches of any strings containing “p1234”. The only place that you will break it now is if you manually added the URL title of “p123”, that wont work. So don’t.

Oh, and the “/ … /” addition to the regular expression is part of the syntax for preg_match (a start and stop character for the expression itself).

(Cross posted to the b2Evolution forums).

You can file issues or provide corrections: View Source on Github. Contributor credits.