-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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 path.normalize not correctly normalizing relative paths #17974
Conversation
89d7fa1
to
4acf24e
Compare
After slicing, the `lastSegmentLength` should be calculated again, instead of assigning value `j`. Fixes: nodejs#17928
4acf24e
to
b1aba4a
Compare
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.
Makes sense to me as @targos is okay with it. Added tests look good.
Removed the confirmed-bug label since that one is usually applied to the issues, not the PRs fixing them |
lib/path.js
Outdated
@@ -29,6 +29,17 @@ function assertPath(path) { | |||
} | |||
} | |||
|
|||
function findLastSlashIndex(path, isWin32) { | |||
var i = path.length - 1; |
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 the logic here can be simplified to Math.max(path.lastIndexOf(isWin32 ? '\\' : '/'), 0)
? Or does iterating over the string with charCodeAt
yield any performance benefit?
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.
Here is just inherited from the logic before. I've just removed it and used lastIndexOf.
Landed in 315d1f5 |
After slicing, the `lastSegmentLength` should be calculated again, instead of assigning value `j`. PR-URL: #17974 Fixes: #17928 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
After slicing, the `lastSegmentLength` should be calculated again, instead of assigning value `j`. PR-URL: #17974 Fixes: #17928 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
After slicing, the `lastSegmentLength` should be calculated again, instead of assigning value `j`. PR-URL: #17974 Fixes: #17928 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
After slicing, the `lastSegmentLength` should be calculated again, instead of assigning value `j`. PR-URL: #17974 Fixes: #17928 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
After slicing, the `lastSegmentLength` should be calculated again, instead of assigning value `j`. PR-URL: #17974 Fixes: #17928 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
After slicing, the
lastSegmentLength
should be calculated again.It should be
(res.length - 1 - lastSlashIndex)
, instead of valuej
.Tests for it is also added.
Fixes: #17928
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
path