-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
process.cwd() casing inconsistent across platforms #8237
Comments
Nice find, I agree the behaviour is wrong there. Likely a Windows API issue. The fact that Powershell displays the "wrong" path doesn't give much hope, though. cc: @nodejs/platform-windows @saghul. |
I believe the behavior is correct, as it returns the path returned by Windows. Regarding the "real path" versus "different case path" issue, I've expressed my opinion in #2443 (comment). To summarize, if you don't expect |
I think it's generally adviceable to do case-insensitive path comparision on case-insensitive file systems. Maybe we should include that in docs somewhere? |
Unfortunately, that raises problems when operating cross-platform. The context here is that on a case-insensitive system (at least in Webpack), it is possible to do Right now I'm planning on working around this by checking what |
For IIRC the problem on Windows is that while NTFS is case sensitive, the Windows API is not, so ¯_(ツ)_/¯ |
To quote a coworker, if Node is supposed to be cross-platform, it should compensate for platform inconsistencies. Much of the I admit this is an edge case, and one that I can probably work around, and even that there is logic in reporting the CWD that the OS reports regardless of whether it is the correct case. In this case that this cannot be resolved, would you at least accept a documentation pull request warning about the cross-platform inconsistency on both |
But which is the correct case if both are valid then? Have you tested with OSX with case-sensitive HFS? Last: in order to fix this Node would need to know what the correct case is (when on Windows), since NTFS is case sensitive. But how do we know? |
By using GetFinalPathNameByHandle. However, I don't think it should be ...Or so it should be in an ideal world. Unfortunately, the JS implementation of > fs.realpathSync('C:\\Users\\Nikolai\\desktop')
'C:\\Users\\Nikolai\\Desktop'
> process.version
'v6.3.1' |
I can't concur that correct case isn't determinate. Even on a case-insensitive system, while many different case combinations might be valid as representations, only one is correct - that is, what the filesystem is actually storing it as. It's the difference between Also, as a side note, I just found out possibly even further evidence in Node itself that case-correctness really does matter. |
As for the "how to determine" question, it's been resolved a couple different ways. The true-case-path lib uses |
@Urthen C:\Users\Nikolai\Desktop>mkdir real
C:\Users\Nikolai\Desktop>mklink /D link real
symbolic link created for link <<===>> real
C:\Users\Nikolai\Desktop>cd link
C:\Users\Nikolai\Desktop\link>node
> process.cwd()
'C:\\Users\\Nikolai\\Desktop\\link'
> fs.realpathSync(process.cwd())
'C:\\Users\\Nikolai\\Desktop\\real' |
While there may not be a unique correct path with respect to symlinks, there is absolutely such thing as a correctly-cased path to a given file (regardless of symlinks) on, as far as I am aware, any modern filesystem. The correct casing is the one reported by @seishun Can I ask why |
Please refer to my example above. Which path would you consider correct in that case?
Because that caused massive breakage, see #7726.
I fail to see a fundamental difference. I can't think of a use case where you need to account for different casing but not for symlinks, or vice versa. |
Sorry, my assertion was unclear. I've clarified. In your example, I'd consider both However, if you then (following the example above, assuming you're in Powershell) did Given the massive breakage, it seems like the difficulties attempting to actually fix this outweigh the relative ease implementing a workaround for quite possibly the only implementation where it is actually enforced. |
That's the path you
Now that's the issue with |
If you read my original issue description, however, you'll note that OSX does not behave that way. |
That seems to be a quirk of OSX to me. What does |
It looks like Node and Python agree between Looks like confirmed as just quirky OS behavior, probably not something Node can reasonably fix. Closing the issue. Thanks for the support. |
We cannot use |
Check this : vitest-dev/vitest#1870 (comment) |
In various case-insensitive platforms - namely, Windows and OSX - it is possible to
cd
into an incorrectly-cased path. Node handles this differently on Windows than it does in OSX when attempting to resolveprocess.cwd()
. This affects other modules - namely, howpath.resolve()
cases its absolute paths.In OSX,
process.cwd()
resolves to the correctly cased path, regardless of which path you havecd
ed into. I believe this to be correct behavior.In Windows default console, it is not possible to
cd
into an incorrect path. However, using PowerShell or the new Bash for Windows, it is possible, butprocess.cwd()
resolves to the incorrect path casing - not matching what is on disk.Again, I feel the OSX behavior is correct, as it matches what is on the filesystem.
The text was updated successfully, but these errors were encountered: