-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
path: fix bugs and inconsistencies #54224
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: fix bugs and inconsistencies #54224
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #54224 +/- ##
==========================================
+ Coverage 87.06% 87.89% +0.83%
==========================================
Files 643 651 +8
Lines 181576 183425 +1849
Branches 34894 35744 +850
==========================================
+ Hits 158088 161222 +3134
+ Misses 16759 15476 -1283
+ Partials 6729 6727 -2
|
| `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`; | ||
| rootEnd = j; | ||
| } else { | ||
| // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should also handle \\?\PHYSICALDRIVE0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other inconsistencies:
path.resolve('\\\\?\\c:/') // \\?\c:
path.toNamespacedPath('c:/') // \\?\c:\
path.normalize('\\\\.\\foo') // \\.\foo\
path.resolve('\\\\.\\foo\\') // \\.\fooThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll try to fix these inconsistencies. I have a question.
Node currently runs as follows:
path.resolve("C:\\") // C:\\
path.resolve("//server/share") // \\\\server\\share\\But, I think it should be:
path.resolve("C:\\") // C:
path.resolve("//server/share") // \\\\server\\shareIf I change these ones, resolve could return all the paths without any trailing backslash.
If I don't change them, the inconsistency below will still exist:
path.resolve("//server/share/folder") // \\\\server\\share\\folder
path.resolve("//server/share") // \\\\server\\share\\What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should respect the original input. If there is a trailing slash, keep it, otherwise do not add it.
$ python
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import PurePath
>>> PurePath('c:/')
PureWindowsPath('c:/')
>>> PurePath('c:')
PureWindowsPath('c:')
>>> PurePath('c:', '\\\\.\\foo')
PureWindowsPath('//./foo')
>>> PurePath('c:', '\\\\.\\foo\\')
PureWindowsPath('//./foo/')
>>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK \\?\... is not supposed to be subject to normalization, see this post.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My latest commit fixes the inconsistencies in resolve, toNamespacedPath and normalize on Windows. I'm open to suggestions and waiting for your reviews.
If there are no objections, I'll fix the inconsistencies between Windows and Posix that occurred after the last commit.
b40e78c to
ab4ad3b
Compare
888faf2 to
69c609d
Compare
4e2dddd to
1601604
Compare
1601604 to
a5540cb
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Is there anything else I can do to help this PR move forward? |
|
@nodejs/path @nodejs/tsc |
|
@huseyinacacak-janea @anonrig @lpinca This change modifies the return results of npm publish error logThe relevant code for the error in npm is as follows: The reason for the error is that the following function returns inconsistent results: // main branch
path.resolve('D:\\1\\xsh\\') === 'D:\\1\\xsh\\'
path.relative('D:\\1\\xsh', 'D:\\1\\xsh\\') === '..\\xsh'
// node.js v22.9.0
path.resolve('D:\\1\\xsh\\') === 'D:\\1\\xsh'
path.relative('D:\\1\\xsh', 'D:\\1\\xsh\\') === '' |
|
Maybe we can limit the scope and go back to b40e78c. |
|
This did not fix that issue, in fact, the fix is a revert of this #55414 |
oops, commented on the wrong PR. deleted the comment to not create confusion. |
This PR fixes resolving device paths like
\\.\PHYSICALDRIVE.The
resolvefunction was adding a trailing backslash, considering that this device path was a UNC path. However, device paths are different than UNC paths.This PR includes more changes than originally intended because fixing the bug caused inconsistencies between other functions and operating systems. Now, this PR fixes all these problems.
Fixes: #54025