Part of the EllisLab Network
   
 
[OPTIMIZATION] URL trailing slash regex in various code files
Posted: 06 May 2007 05:48 AM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  472
Joined  09-26-2006

Libraries/Calendar.php, Line 163, replace A with B. (This is the same as Geert’s first posted opt, so should be good)
A :

// Add a trailing slash to the  URL if needed
    
$this->next_prev_url = preg_replace("/(.+?)\/*$/", "\\1/",  $this->next_prev_url);

B :

// Add a trailing slash to the URL if needed
       
$this->next_prev_url = rtrim($this->next_prev_url, '/') .'/';
 Signature 

Old programmers never die, they just parse away.

Profile
 
 
Posted: 06 May 2007 08:39 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  735
Joined  10-18-2006

The same preg is used in Calendar (163), FTP (378), Pagination (149) and Upload (624). I think this thread could be for all those lines…

 Signature 

Once in a while I remember I use Twitter

Profile
 
 
Posted: 06 May 2007 08:57 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  472
Joined  09-26-2006

Good Idea Seppo, I’ve updated the post title to cater for that.

 Signature 

Old programmers never die, they just parse away.

Profile
 
 
Posted: 06 May 2007 11:15 AM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  248
Joined  02-10-2007

A similar update needs to happen in the Config library.

/**
* Fetch a config file item - adds slash after item
*
* The second parameter allows a slash to be added to the end of
* the item, in the case of a path.
*
* @access    public
* @param    string    the config item name
* @param    bool
* @return    string
*/        
function slash_item($item)
{
    
if ( ! isset($this->config[$item]))
    
{
        
return FALSE;
    
}
    
    $pref
= $this->config[$item];
    
    if (
$pref != '')
    
{    
        
// REMOVED:
        // if (ereg("/$", $pref) === FALSE)
        // {
        //    $pref .= '/';
        // }
        
        // ADDED:
        
$pref = rtrim($pref, '/') .'/';
    
}

    
return $pref;
}

By the way, it would be great to get rid of all the ereg() functions. If you need to use regex, PCRE is the way to go (preg_functions).

 Signature 

Kohana rocks!

Profile
 
 
Posted: 07 May 2007 07:53 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  248
Joined  02-10-2007

Another one in Config.php line 209:

... preg_replace("|^/*(.+?)/*$|", "\\1", $uri) ...

Change to:

... trim($uri, '/') ...
 Signature 

Kohana rocks!

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 77571 Total Logged-in Users: 22
Total Topics: 101562 Total Anonymous Users: 2
Total Replies: 544410 Total Guests: 190
Total Posts: 645972    
Members ( View Memberlist )
Newest Members:  Idril616tonybernardcarterstarksColeJLinskitnealsemperjrawhallshiusbozzlynobluff