fix: use .exe PATH fallback so PATHEXT cannot run node.js - #191
Closed
dyk1454683243-sudo wants to merge 1 commit into
Closed
dyk1454683243-sudo wants to merge 1 commit into
dyk1454683243-sudo wants to merge 1 commit into
Conversation
cmd.exe PATHEXT-expands extensionless names (cwd first). Default PATHEXT includes .JS, so a sibling node.js is executed instead of node. The existing %PATHEXT:;.JS;=;% strip only removes a middle ;.JS; entry. Look up simple command names as prog.exe (node.exe, python.exe), matching the local %dp0%\prog.exe check and the PowerShell $exe suffix. Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
Author
|
Withdrawing this PR while I clean up a high-volume open-PR backlog. Sorry for the noise — happy to come back later with a focused change if useful. |
This file contains hidden or 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
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.
Fixes #71
Cause
On Windows, cmd.exe resolves an extensionless command by searching the current directory first, then
PATH, appending eachPATHEXTentry. DefaultPATHEXTincludes.JS, so a file namednode.jsin cwd (or earlier onPATH) is executed instead ofnode.exe. Asking users to remove.JSfromPATHEXTis not acceptable — it is the Windows default.#64 moved
set PATHEXT=%PATHEXT:;.JS;=;%to afterendLocalso the strip can take effect. That substitution only removes a middle;.JS;entry. It does not remove.JSwhen it is first (.JS;.COM;...) or last (.COM;...;.JS). The PATH fallback remained the extensionless namenode, so any failed or partial strip still launchesnode.js. The same search applies to other env bins (python→python.js).Fix
When the interpreter is a simple command name, the
.cmdshim PATH fallback is nowprog.exe(node.exe,python.exe) instead ofnode. cmd.exe looks up that exact name and cannot matchnode.js.This matches the existing
%dp0%\node.execheck and the PowerShell shim (node$exe→node.exeon Windows)..exeare left as-is/usr/bin/sh) are unchanged (not PATHEXT-searched)PATHEXT.JSstrip is kept as defense in depthTests
nodeis shadowed bynode.js;node.exeis not, including when.JSis first or last.cmdshims assertSET "_prog=node.exe"/python.exeSeparate from #190 (UTF-8 BOM). No open PR already claimed #71.