Skip to content

Commit

Permalink
Bug fix for relative directory removal
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chernjie committed Dec 6, 2012
1 parent fd24adf commit af3bd3e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion system/core/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,26 @@ 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_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);
}

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

0 comments on commit af3bd3e

Please sign in to comment.