Skip to content

Commit

Permalink
Merge pull request bcit-ci#2055 from chernjie/develop
Browse files Browse the repository at this point in the history
Bug fix for relative directory removal
  • Loading branch information
narfbg committed Dec 6, 2012
2 parents fd24adf + 0bf9cfa commit 3fd3345
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion system/core/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,32 @@ protected function _parse_request_uri()
}

// Do some final cleaning of the URI and return it
return str_replace(array('//', '../'), '/', trim($uri, '/'));
return $this->_remove_relative_directory($uri);
}

// --------------------------------------------------------------------

/**
* Remove relative directory (../) and multi slashes (///)
*
* Do some final cleaning of the URI and return it, currently only used in self::_parse_request_uri()
*
* @param string $url
* @return string
*/
protected function _remove_relative_directory($uri)
{
$uris = array();
$tok = strtok($uri, '/');
while ($tok !== FALSE)
{
if (( ! empty($tok) OR $tok === '0') && $tok !== '..')
{
$uris[] = $tok;
}
$tok = strtok('/');
}
return implode('/', $uris);
}

// --------------------------------------------------------------------
Expand Down

0 comments on commit 3fd3345

Please sign in to comment.