Skip to content

Fix path resolver when path start with directory separator #509

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

Merged
merged 1 commit into from
Jul 11, 2021

Conversation

50bhan
Copy link
Contributor

@50bhan 50bhan commented Jun 22, 2021

Q A
Bug fix? yes
New feature? no
Fixed tickets #508

This PR will close #508.

@50bhan 50bhan force-pushed the bug/fix-path-resolver branch 3 times, most recently from 3969bd7 to 7e84090 Compare June 22, 2021 16:26
Copy link
Collaborator

@Jibbarth Jibbarth left a comment

Choose a reason for hiding this comment

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

Hey @50bhan, just tested your implementation.

Given PHPInsights is installed globally, I execute it from my HOME directory.

$ phpinsights analyse /tmp/app 

This work and launch the analyse on the expected directory

$ phpinsights analyse /tmp

This doesn't work, raise the following exception :

  The "/home/barth/tmp" directory does not exist.  

So we have a regression here

public function testResolvePathWithDirectorySeparator(): void
{
$path = '/app';
$sanitizedPath = getcwd() . $path;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's incorrect.

If I provide an absolute path (like /app), this shouldn't be resolved as current working dir + app.

@Jibbarth
Copy link
Collaborator

Jibbarth commented Jul 4, 2021

@50bhan, for me, the bug is here https://github.com/nunomaduro/phpinsights/blob/master/src/Infrastructure/Repositories/LocalFilesRepository.php#L66

Could be resolved like this

$this->directoryList[] = rtrim($pathInfo['dirname'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $pathInfo['basename'];

But I'm not sure it'll work on Windows.

@50bhan
Copy link
Contributor Author

50bhan commented Jul 4, 2021

@50bhan, for me, the bug is here https://github.com/nunomaduro/phpinsights/blob/master/src/Infrastructure/Repositories/LocalFilesRepository.php#L66

Could be resolved like this

$this->directoryList[] = rtrim($pathInfo['dirname'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $pathInfo['basename'];

But I'm not sure it'll work on Windows.

Actually, this isn't the correct workaround. At first, I did the exact change that you've made. But the problem still remains:

Screen Shot 2021-07-04 at 23 47 47

@Jibbarth
Copy link
Collaborator

Jibbarth commented Jul 4, 2021

@50bhan i think it's the expected behaviour. When we pass an absolute path, it should be used.

But in the LocalFileRepository, it transform /app into //app

@50bhan
Copy link
Contributor Author

50bhan commented Jul 4, 2021

@Jibbarth I was confused about it. If this is the case, the fix is easy as you said. I'll update the PR.

@Jibbarth
Copy link
Collaborator

Jibbarth commented Jul 4, 2021

Great ! If I found a Windows, I'll test against

@50bhan 50bhan force-pushed the bug/fix-path-resolver branch from 7e84090 to c82cc16 Compare July 4, 2021 20:16
@50bhan
Copy link
Contributor Author

50bhan commented Jul 4, 2021

@Jibbarth Thanks, it would be awesome. I updated the PR.

Edit: Needed to upgrade Rector to avoid CI failure.

@50bhan 50bhan force-pushed the bug/fix-path-resolver branch 3 times, most recently from 9e11b9c to 6f5225f Compare July 4, 2021 20:41
@50bhan 50bhan force-pushed the bug/fix-path-resolver branch from 6f5225f to 2abfb75 Compare July 4, 2021 20:56
Copy link
Collaborator

@Jibbarth Jibbarth left a comment

Choose a reason for hiding this comment

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

Tested on Windows, bug was also present and now it's fixed 🎉

Thank you @50bhan 🙏

@Jibbarth Jibbarth merged commit 12cf538 into nunomaduro:master Jul 11, 2021
@50bhan 50bhan deleted the bug/fix-path-resolver branch July 11, 2021 12:54
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.

Directory file paths have double DIRECTORY_SEPARATOR
2 participants