404 errordocument handling

Found a bug? Tell us!!
Post Reply
munk
Regular
Posts: 15
Joined: Tue Dec 09, 2003 6:25 pm
Contact:

404 errordocument handling

Post by munk »

Hi,

First up thanks for a great blog :P

I've just been playing with s9y for a few days now and all is great apart from the following:

If a user enters an invalid (404) URI, the code in index.php appears to still divert the user to the index page instead of displaying the 404 error message as it presumably is supposed to. From what I can see this is because of the following code from index.php - line 132 onwards:

Code: Select all

} else if (preg_match('@/categories/(.*)@', $uri, $matches) ||
           preg_match('@/(index\.(php|html))?@', $uri) ||
           preg_match('@/(' . preg_quote($serendipity['indexFile']) . ')?@', $uri)) {
I believe this code should evaluate to false if an invalid URI is entered but instead always evaluates true as long as the URI contains a forward slash (/) - which is always given the way most web browsers work.

For example this URI:

http://blog.munk.nu/nonexistent

should presumably invoke the 'catchall' code in index.php:

Code: Select all

} else {
    printf(DOCUMENT_NOT_FOUND, $uri);
}
however it doesn't and instead displays the 'default' page listing.

From what I can tell this is because of the pcre '?' in the regexps in the first 2 preg_match statements - changing the code to this has the desired effect:

Code: Select all

} else if (preg_match('@/categories/(.*)@', $uri, $matches) ||
           preg_match('@/(index\.(php|html))@', $uri) ||
           preg_match('@/(' . preg_quote($serendipity['indexFile']) . ')@', $uri)) {
ie invalid URIs DO invoke the 404 error code with this ammendment.

Should the '?' be removed or just be escaped? Or am I totally wrong? :oops:

TIA
tomsommer
Core Developer
Posts: 240
Joined: Tue Sep 02, 2003 6:43 pm
Location: Denmark
Contact:

Post by tomsommer »

Please post a bug in sourceforge, for better tracking :)
Tom Sommer (Serendipity Core Developer)
http://blog.dreamcoder.dk
munk
Regular
Posts: 15
Joined: Tue Dec 09, 2003 6:25 pm
Contact:

Post by munk »

Ok.
Post Reply