-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix for relative directory removal #2055
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No private methods please (protected is good) - this makes it impossible to extend parts of the core. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For readability, would you prefer if it's merged into the previous method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless it would be used elsewhere - yes, otherwise it doesn't make sense (functionally). Just leave a comment above it to describe what it does. |
||
{ | ||
$uris = array(); | ||
$tok = strtok($url, '/'); | ||
while ($tok !== false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. false -> FALSE Also might be a good idea to just do this and remove lines 235 & 239 (the latter doesn't seem correct anyway - shouldn't
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to PHP manual: http://php.net/manual/en/function.strtok.php
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, agreed. |
||
{ | ||
($tok != '..' && ! empty($tok) || $tok === '0') && $uris[] = $tok; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one looks really weird, should be converted to an if, with several style changes:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not work :( $ time php UnitTest-e8af5d1.php | grep -E '^F'
F 0/abc
F abc/0
F abc/0/def There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, my fault ... should've been this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay fixed, committing now |
||
$tok = strtok('/'); | ||
} | ||
return implode('/', $uris); | ||
} | ||
|
||
// -------------------------------------------------------------------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use only tabs as separators - no spaces (between 'string' and '$url' + although followed by a tab, you have spaces after both
@param
and@return
).Additionally, for the sake of consistency there should be an empty description line between 228 & 229.