-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Windows: fix escaping of external commands #3214
Merged
gsherwood
merged 1 commit into
squizlabs:master
from
jrfnl:feature/windows-fix-running-external-progs
Feb 14, 2021
Merged
Windows: fix escaping of external commands #3214
gsherwood
merged 1 commit into
squizlabs:master
from
jrfnl:feature/windows-fix-running-external-progs
Feb 14, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The `escapeshellcmd()` function apparently does not escape spaces within a path on Windows which can result in broken functionality. While the sniffs and report affected by this are apparently not used that much based on the lack of bug reports, fixing it still seemed like the _right thing to do_. Noticed while running the unit tests on a fresh install on Windows 10. At some point over the past years, Node has apparently changed their default install directory on Windows and the order in which they register their paths to the Windows system `PATH`. This means that `where csslint` may result in a `$cmd` path like `C:\Program Files\nodejs\csslint.cmd`, which would be escaped to `C:^\Program Files^\nodejs^\csslint.cmd` on Windows, which in turn results in a `'C:\Program' is not recognized as an internal or external command, operable program or batch file.` error. I could have changed the install path for NVM on my machine, but that would just have hidden the underlying issue. It does appear to be a known issue with the function based on the last two comments in this upstream bug report: https://bugs.php.net/bug.php?id=43261, however as that issue is closed, I don't expect this to be fixed in PHP itself, though it might be worth it to open a new issue upstream about it (as those two comments were left on a closed issue years after the close). Fixed now by checking an escaped path for unescaped spaces when on Windows and if necessary, escaping them. The escaping is done in such a way that, even if PHP itself would start escaping these spaces, the `Common::escapeshellcmd()` function will still handle this correctly.
There are still 3 of these paths in version 4, so very much worth doing. Thanks. |
Yvw |
jrfnl
added a commit
to jrfnl/doc-en
that referenced
this pull request
Apr 2, 2021
It is a known issue that spaces are not escaped in shell commands, which can be especially problematic on Windows. This adds a warning about this behaviour to the function, including a way to solve this in userland code. Ref: https://bugs.php.net/bug.php?id=43261 (last two comments) Also see: squizlabs/PHP_CodeSniffer#3214
jrfnl
added a commit
to jrfnl/doc-en
that referenced
this pull request
Apr 2, 2021
It is a known issue that spaces are not escaped in shell commands, which can be especially problematic on Windows. This adds a warning about this behaviour to the function, including a way to solve this in userland code. Ref: https://bugs.php.net/bug.php?id=43261 (last two comments) Also see: squizlabs/PHP_CodeSniffer#3214
cmb69
pushed a commit
to php/doc-en
that referenced
this pull request
Apr 5, 2021
It is a known issue that spaces are not escaped in shell commands, which can be especially problematic on Windows. This adds a warning about this behaviour to the function, including a way to solve this in userland code. Ref: https://bugs.php.net/bug.php?id=43261 (last two comments) Also see: squizlabs/PHP_CodeSniffer#3214 Co-authored-by: jrfnl <[email protected]>
mumumu
added a commit
to php/doc-ja
that referenced
this pull request
Apr 8, 2021
It is a known issue that spaces are not escaped in shell commands, which can be especially problematic on Windows. This adds a warning about this behaviour to the function, including a way to solve this in userland code. Ref: https://bugs.php.net/bug.php?id=43261 (last two comments) Also see: squizlabs/PHP_CodeSniffer#3214 Co-authored-by: jrfnl <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
escapeshellcmd()
function apparently does not escape spaces within a path on Windows which can result in broken functionality.While the sniffs and report affected by this are apparently not used that much based on the lack of bug reports, fixing it still seemed like the right thing to do.
Noticed while running the unit tests on a fresh install on Windows 10.
At some point over the past years, Node has apparently changed their default install directory on Windows and the order in which they register their paths to the Windows system
PATH
.This means that
where csslint
may result in a$cmd
path likeC:\Program Files\nodejs\csslint.cmd
, which would be escaped toC:^\Program Files^\nodejs^\csslint.cmd
on Windows, which in turn results in a'C:\Program' is not recognized as an internal or external command, operable program or batch file.
error.I could have changed the install path for NVM on my machine, but that would just have hidden the underlying issue.
It does appear to be a known issue with the function based on the last two comments in this upstream bug report: https://bugs.php.net/bug.php?id=43261, however as that issue is closed, I don't expect this to be fixed in PHP itself, though it might be worth it to open a new issue upstream about it (as those two comments were left on a closed issue years after the close).
Fixed now by checking an escaped path for unescaped spaces when on Windows and if necessary, escaping them.
The escaping is done in such a way that, even if PHP itself would start escaping these spaces, the
Common::escapeshellcmd()
function will still handle this correctly.