diff options
author | chernjie <chernjie@gmail.com> | 2012-12-06 05:06:50 +0100 |
---|---|---|
committer | CJ <chern.jie@mig33global.com> | 2012-12-06 06:28:22 +0100 |
commit | af3bd3e57fa7b381a670d3b96d9bb49d142739c8 (patch) | |
tree | f11a9fd5ee36aeeb41dd051fefd676c27870195f /system/core/URI.php | |
parent | fd24adf31255822d6aa9a5d2dce9010ad2ee4cf0 (diff) |
Bug fix for relative directory removal
This fixes two bugs:
- for segments that ends with ".." e.g. /user/username../details, this should not be replaced
- current solution only replace double slashes, this solutions removes the infinite number of recurring slashes
Diffstat (limited to 'system/core/URI.php')
-rw-r--r-- | system/core/URI.php | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/system/core/URI.php b/system/core/URI.php index 91740254c..3f8775d4e 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -219,7 +219,26 @@ class CI_URI { } // Do some final cleaning of the URI and return it - return str_replace(array('//', '../'), '/', trim($uri, '/')); + return $this->_remove_relative_directory_str($uri); + } + + // -------------------------------------------------------------------- + + /** + * Remove relative directory (../) and multi slashes (///) + * @param string $url + * @return string + */ + private function _remove_relative_directory_str($url) + { + $uris = array(); + $tok = strtok($url, '/'); + while ($tok !== false) + { + ($tok != '..' && ! empty($tok) || $tok === '0') && $uris[] = $tok; + $tok = strtok('/'); + } + return implode('/', $uris); } // -------------------------------------------------------------------- |