-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Path.resolve reports the wrong path for junctioned paths in windows. #22592
Comments
What is the value of |
Code:
Result:
So |
The issue here is that You can try |
Looking at https://nodejs.org/docs/latest/api/modules.html#modules_dirname, which points us to https://nodejs.org/docs/latest/api/modules.html#modules_filename, there is no mention what this value is supposed to be other than an "absolute path", which does not say what it does (or rather, what it defines as what will happen) on symlinks and junctions. So I'll file a new issue for that. Thanks for the help. |
Running
Path.resolve
on a junctioned path in Windows 10 yields the "true" path, rather than the path that as seen from the working directory. This means that anything that checks whether a path is located relative to another path may fail, even though the junctions were set up in a way where this should absolutely not be the case.This is particularly obvious when running web servers with static directories, so a demonstrator:
D:\junctions\git\test\
dirC:\Users\YourName\Documents\
, create a directory junctiongit
<==>D:\junctions\git
C:\Users\YourName\Documents\git\test
node test.js
While this should output
C:\Users\YourName\Documents\git\test\
, because that's what symlinks/junctions are used for (using paths as if they are local to somewhere they are not local to) it will instead output the originalD:\junctions\git\projects\test
path.For a practical demonstration of how this ruins the fun, the Hapi
inert
middleware (responsible for static file serving) grinds to a halt on this because it sees an attempt to load a file that we as users think we've housed in a project-local directory, exceptPath.resolve
turns that local path into a path on a completely different drive, massively violating containment rules and leading to a situation that requires diving intonode_modules
dir and debugging code two dependencies deep, only to find Node itself is doing the wrong thing =)So, as the documentation for
Path.resolve
does not mention what it will do with symlinks, this is both a bug report and a request:Path.resolve
so that it generates a proper path, only asking for the true resource path belonging to a symlink/junction when an option is passed to enable that? And,Path.resolve
to mention what it does when it encounters a symlink or junction, so that developers know what behaviour can be expected from the Path module when it comes to "fake paths"?The text was updated successfully, but these errors were encountered: