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

Fix the php executable to handle folder name with spaces #171

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

dingo-d
Copy link

@dingo-d dingo-d commented Apr 11, 2024

@jrfnl
Copy link
Collaborator

jrfnl commented Apr 11, 2024

@dingo-d Thanks for this PR. I haven't looked at the code yet, but there have been two other PRs - #147 and #149 - not too long ago which attempted to do the same, but not always correctly. Could you please check that your PR avoids the problems those PRs had ?

@dingo-d
Copy link
Author

dingo-d commented Apr 12, 2024

@jrfnl I don't think this PR has the same problems as those two PRs. In one, the author was adding escaping around executable, and in another there was a whole new method for escaping the binary path.

In this PR the only change is wrapping the executable in quotes so that the spaces in the paths are correctly handled.

I don't have a windows based dev environment to test if this solution works there tho.

@dingo-d
Copy link
Author

dingo-d commented May 16, 2024

@jrfnl I fixed the failed phpcs check, additional tests are passing, so I think this should be good to go.

@jrfnl
Copy link
Collaborator

jrfnl commented May 16, 2024

I fixed the failed phpcs check, additional tests are passing, so I think this should be good to go.

@dingo-d Thanks for that! I've just looked this over and these are my findings:

  1. While I agree the test you added has value, it doesn't actually test your change.
  2. When looking at that test, I wonder if some additional test cases should be added with Windows paths ? (forward slashes and paths quoted on the command line) Outside the scope for this PR, but would be good to safeguard that more for the future.

Back to the actual proposed change.

This change is about the path to the PHP executable containing spaces. I'm not actually sure if this can be tested via the test suite easily. Then again, you might be able to test it by making a copy of the executable file and then adding a space in the file path or something. Or maybe by creating a symbolic link where the symbolic link has a space in the path ?

Having said that, I think we may first need to have a good reproduction case anyhow as I haven't been able to make this fail on Windows in the first place (using the develop branch).

How I tested:

  1. Rename the directory on my system which contains the PHP executable I'm going to use for the tests to /php 8.3.7/ (note the space in the path)
  2. Updated the Windows Path environment variable to include this new path and no other path to PHP.
  3. Added a var_dump($executable) on the line above the change to verify that the path to PHP being used is the one with the space in it.
  4. Ran php ./parallel-lint ./src/errors/ from the root of this repo - this should use the system default PHP version, which should now be the PHP executable in the /php 8.3.7/ path. All okay.
  5. Ran "C:\wamp\bin\php\php 8.3.7\php.exe" ./parallel-lint ./src/errors/ - this makes the path to PHP explicit. Same thing, all okay.
  6. Did the same, but without quoting the path to PHP - got an (expected) Windows error about not being able to execute the command as it doesn't read past the space.

image

So, on develop I wasn't able to reproduce the issue, which means I can't verify the fix. Having said that, I do believe the fix is correct, though I wonder if any protection is needed against "double quoting", i.e. quoting a path which is already quoted ?

Maybe some people who are having this problem can outline a reproduction scenario ?
/cc @ElRochito @azatakmyradov @piqusy

@dingo-d
Copy link
Author

dingo-d commented May 20, 2024

Having said that, I think we may first need to have a good reproduction case anyhow as I haven't been able to make this fail on Windows in the first place (using the develop branch).

I agree, but the failure affected macOS specifically so Windows not failing is a good sign. And with the proposed change, I tested that it's working on macOS.

I've renamed the path to my PHP to include a space:

image

Then ran the tests on the branch with the fix and on the develop branch, and I get the error in the develop branch, but not this one with the fix:

image

@jrfnl jrfnl force-pushed the bugfix/correctly-wrap-executable branch from b0c432a to 75bf94b Compare May 20, 2024 10:22
@jrfnl
Copy link
Collaborator

jrfnl commented May 20, 2024

Rebased without changes to get a passing build after #174.

@jrfnl
Copy link
Collaborator

jrfnl commented May 20, 2024

@dingo-d Thank you for sharing your test results. I didn't realize it was about MacOS, not Windows.

As the unit test doesn't really belong with this PR, do you want to move that contribution to a separate PR ?

Note: it's not a blocker, but it will prevent confusion about what the test is testing if someone does a git blame in the future.

@dingo-d dingo-d force-pushed the bugfix/correctly-wrap-executable branch from 75bf94b to 5003653 Compare May 20, 2024 11:49
As reported in beyondcode/herd-community#631.

Co-authored-by: Marcel Pociot <804684+mpociot@users.noreply.github.com>
@dingo-d dingo-d force-pushed the bugfix/correctly-wrap-executable branch from 5003653 to db1fbdf Compare May 20, 2024 11:51
@dingo-d
Copy link
Author

dingo-d commented May 20, 2024

@jrfnl I've removed the tests (I made a separate branch for those tests so I'll make a separate PR for that), and rebased to one commit. Hope it's ok now 👍🏼

Copy link
Collaborator

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Thanks @dingo-d ! All good AFAICS.

@jrfnl jrfnl added this to the 1.4.x Next milestone May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants