Skip to content
Browse files

Fixed slash_item bug

  • Loading branch information...
1 parent 2e5b666 commit 9ce4dcbe827137bc3b5f7283407771592979a1cb @williamhrs committed Jan 19, 2011
Showing with 15 additions and 12 deletions.
  1. +15 −12 system/core/Config.php
View
27 system/core/Config.php
@@ -188,23 +188,26 @@ function item($item, $index = '')
/**
* 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;
- }
+ {
+ if ( ! isset($this->config[$item]))
+ {
+ return FALSE;
+ }
- return rtrim($this->config[$item], '/').'/';
- }
+ $pref = $this->config[$item];
+
+ if ($pref != '' && substr($pref, -1) != '/')
+ {
+ $pref .= '/';
+ }
+
+ return $pref;
+ }
// --------------------------------------------------------------------
@@ -309,4 +312,4 @@ function _assign_to_config($items = array())
// END CI_Config class
/* End of file Config.php */
-/* Location: ./system/core/Config.php */
+/* Location: ./system/core/Config.php */

4 comments on commit 9ce4dcb

@philsturgeon

What was the bug? It looks like you've just replaced the rtim() with a slightly slower method, unless I'm missing something?

@williamhrs
Owner

all URLS were getting an extra slash at the end.

like

localhost/app//method
instead of
localhost/app/method.

@philsturgeon

Ahh I had that too, fixed but not pushed. My solution was http://scrp.at/q6

Notice that I am only slashing index if it exists. There is no point turning "" into "/" if we already know that the base URL has a / on the end, right?

@williamhrs
Owner

Right! :D
going to change mine! :D thx dude!

Please sign in to comment.
Something went wrong with that request. Please try again.