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
diff --git a/system/core/URI.php b/system/core/URI.php
index 9174025..3f8775d 100644
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -219,7 +219,26 @@
 		}
 
 		// 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);
 	}
 
 	// --------------------------------------------------------------------