xdebug-handler icon indicating copy to clipboard operation
xdebug-handler copied to clipboard

Support php binary path with whitespaces

Open jkrzefski opened this issue 1 year ago • 1 comments

I am using Laravel Herd for my local PHP environment. That means, that my PHP binary is located in /Users/jkrzefski/Library/Application Support/Herd/bin/php82. As you can see, there is a whitespace in the path.

When the XdebugHandler attempts to restart the command, the path to the binary must be escaped, because otherwise I get the following error message:

sh: /Users/jkrzefski/Library/Application: No such file or directory

jkrzefski avatar Dec 15 '23 08:12 jkrzefski

The array returned from getCommand is either escaped by PHP (from 7.4) or by Process::escapeShellCommand. Which PHP version are you running?

Edit:

Sorry, missed the ..bin/php82 bit.

johnstevenson avatar Dec 15 '23 12:12 johnstevenson

Sorry, but we cannot use this PR because you are escaping a value which could be escaped again later.

Looking into the PHP source code, on PHP 7.4 and upwards no escaping is done on non_windows platforms due to the way those platforms create a new process. However, I've tested running a binary from a path with spaces in it (only on Ubuntu) and it works fine.

In fact adding any form of escaping to the binary, which you would need to do if running it through a shell (enclosing it in single or double quotes, or using a backslash to escape the space) causes it to fail.

Furthermore, your error message doesn't really make sense, because the shell (from sh) should not be involved on PHP 7.4 and upwards:

sh: /Users/jkrzefski/Library/Application: No such file or directory

I'm afraid I have no idea of what is going on here. Have you reported it to Laravel Herd?

johnstevenson avatar Mar 17 '24 20:03 johnstevenson