- b2evolution CMS Support Forums
- Archives
- Older bugs
- Bugs in versions 0.x
- "p<number>" in permalinks bug (and patch).
1 shovel Jan 31, 2005 00:26
A bug exists in 0.9.0.10 whereby a permanlink to an entry with a URL title beginning with "php4" would cause the PHP error "Call to a member function on a non-object".
In fact, this bug would apply to any permalink beginning with a p<number> format due to a loose regular expression in _blog_main.php. Out-Of-Box, it conflicts with the "p<postnumber>" syntax for accessing a post by numerical id.
I don't know if this was resolved in .11, but here's a fix (from [url=http://blog.ben-ward.co.uk]my blog[/url]).
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).
Or, you can use the follow patch that I generated from Eclipse. I have no idea how useful it is in this form as I've never made one before. Y'never know though...
I hope this is welcome. Good lunch on continued development.
Index: D:/bmpw/Documents/Dev/Eclipse Workspace/Ben Ward.co.uk/blog/b2evocore/_blog_main.php
===================================================================
--- D:/bmpw/Documents/Dev/Eclipse Workspace/Ben Ward.co.uk/blog/b2evocore/_blog_main.php (revision 8)
+++ D:/bmpw/Documents/Dev/Eclipse Workspace/Ben Ward.co.uk/blog/b2evocore/_blog_main.php (working copy)
@@ -109,7 +109,7 @@
$tb=1; // Display trackbacks
$pb=1; // Display pingbacks
- if( ereg( "p([0-9]+)", $path_elements[$i], $req_post ) )
+ if( preg_match( "/^p([0-9]+)$/", $path_elements[$i], $req_post ) )
{ // The last param is of the form p000
// echo 'post number';
$p = $req_post[1]; // Post to display
3 shovel Jan 31, 2005 00:49
Aha, well. In that case I hope this is useful to anyone that is stuck on a .10 install for any reason. :)
Shovel wrote:
Apparently yes. I just took an unadulterated v10 installation and duplicated the error. Yesterday I was not able to when working in a v11 installation. Same server, same title.