Skip to content
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

Do not check the existence of stdin-path when processing data from STDIN #1489

Closed

Conversation

withwind8
Copy link

#1488

realpath is used to get canonicalized absolute pathname, whether to specify the file directly or to use STDIN with --stdin-path specified, and it will check the existence of the file.

In my opinion, it is not necessary to check the existence of stdin-path when processing data from STDIN. If you want, just specify the file instead of using STDIN.

This PR provides a new function to get canonicalized absolute pathname and not check existence. When processing data from STDIN with --stdin-path specified, use the new function.

@gsherwood gsherwood added this to the 3.1.0 milestone Jun 11, 2017
Copy link
Contributor

@ktomk ktomk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left some comments in review while taking a look at some issues.

}

// Replace backslashes with forwardslashes.
$path = str_replace('\\', '/', $path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use strtr

// Replace backslashes with forwardslashes.
$path = str_replace('\\', '/', $path);
// Combine multiple slashes into a single slash.
$path = preg_replace('/\/+/', '/', $path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could canonicalize backslashes with this as well in one. Combining multiple slashes is much appreceated.

{
// Don't prefix absolute paths.
if (substr($path, 0, 1) !== '/') {
$path = getcwd().'/'.$path;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getcwd will do a realpath (which might not be what you want according to the issue). You perhaps want to optionally inject that value as a parameter (which would allow to process on getenv("PWD") or some other OS-specific strategy to obtain the working directory).

// Ignore parts that have no value.
if (empty($part) === true || $part === '.') continue;
if ($part !== '..') {
// Cool, we found a new part.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's neither cool nor do we find anything here. Perhaps just $parts[] = $path;

if ($part !== '..') {
// Cool, we found a new part.
array_push($parts, $part);
} else if (count($parts) > 0) {
Copy link
Contributor

@ktomk ktomk Jul 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean $part === '..' I guess ....

// Going back up.
array_pop($parts);
} else {
// Path is outside of the root.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is not. It actually is root then.

*
* @return mixed
*/
public static function realpath($path)
public static function realpath($path, $isStdin=false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional helper parameter, consider to instead create a second function and call that second function when intended (functional decomposition instead of conditional code).

Copy link
Contributor

@ktomk ktomk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left some comments in review while taking a look at some repo issues. Please don't see the comments as must-have, I'm not associated with the project itself. Just take out of it what is helpful for you.

@gsherwood
Copy link
Member

I don't like the idea of trying to expand references inside a fake file path like this. It also needs to be compatible with Windows paths and it doesn't look like it would be. I'm going to close this PR and attempt another solution, but I'll comment on the main issue.

@gsherwood gsherwood closed this Jul 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants