Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

Projects
None yet
7 participants
@starkwang
Copy link
Contributor

commented Jan 4, 2018

After slicing, the lastSegmentLength should be calculated again.
It should be (res.length - 1 - lastSlashIndex), instead of value j.

Tests for it is also added.

Fixes: #17928

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

path

@starkwang

This comment has been minimized.

Copy link
Contributor Author

commented Jan 4, 2018

@starkwang starkwang force-pushed the starkwang:fix-path-normalize branch 2 times, most recently from 89d7fa1 to 4acf24e Jan 4, 2018

@starkwang

This comment has been minimized.

Copy link
Contributor Author

commented Jan 4, 2018

path: fix path.normalize not correctly normalizing relative paths
After slicing, the `lastSegmentLength` should be calculated again,
instead of assigning value `j`.

Fixes: #17928

@starkwang starkwang force-pushed the starkwang:fix-path-normalize branch from 4acf24e to b1aba4a Jan 4, 2018

@targos

targos approved these changes Jan 7, 2018

@gibfahn

gibfahn approved these changes Jan 7, 2018

Copy link
Member

left a comment

Makes sense to me as @targos is okay with it. Added tests look good.

@joyeecheung

This comment has been minimized.

Copy link
Member

commented Jan 9, 2018

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;

This comment has been minimized.

Copy link
@joyeecheung

joyeecheung Jan 9, 2018

Member

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?

This comment has been minimized.

Copy link
@starkwang

starkwang Jan 10, 2018

Author Contributor

Here is just inherited from the logic before. I've just removed it and used lastIndexOf.

@starkwang

This comment has been minimized.

Copy link
Contributor Author

commented Jan 10, 2018

@starkwang

This comment has been minimized.

Copy link
Contributor Author

commented Jan 11, 2018

Landed in 315d1f5

@starkwang starkwang closed this Jan 11, 2018

starkwang added a commit that referenced this pull request Jan 11, 2018

path: fix path.normalize for relative paths
After slicing, the `lastSegmentLength` should be calculated again,
instead of assigning value `j`.

PR-URL: #17974
Fixes: #17928
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>

@TimothyGu TimothyGu removed the author ready label Jan 13, 2018

evanlucas added a commit that referenced this pull request Jan 22, 2018

path: fix path.normalize for relative paths
After slicing, the `lastSegmentLength` should be calculated again,
instead of assigning value `j`.

PR-URL: #17974
Fixes: #17928
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>

evanlucas added a commit that referenced this pull request Jan 30, 2018

path: fix path.normalize for relative paths
After slicing, the `lastSegmentLength` should be calculated again,
instead of assigning value `j`.

PR-URL: #17974
Fixes: #17928
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>

msoechting added a commit to hpicgs/node that referenced this pull request Feb 5, 2018

path: fix path.normalize for relative paths
After slicing, the `lastSegmentLength` should be calculated again,
instead of assigning value `j`.

PR-URL: nodejs#17974
Fixes: nodejs#17928
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>

msoechting added a commit to hpicgs/node that referenced this pull request Feb 7, 2018

path: fix path.normalize for relative paths
After slicing, the `lastSegmentLength` should be calculated again,
instead of assigning value `j`.

PR-URL: nodejs#17974
Fixes: nodejs#17928
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>

MylesBorins added a commit that referenced this pull request Feb 27, 2018

path: fix path.normalize for relative paths
After slicing, the `lastSegmentLength` should be calculated again,
instead of assigning value `j`.

PR-URL: #17974
Fixes: #17928
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>

MylesBorins added a commit that referenced this pull request Feb 27, 2018

path: fix path.normalize for relative paths
After slicing, the `lastSegmentLength` should be calculated again,
instead of assigning value `j`.

PR-URL: #17974
Fixes: #17928
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>

@MylesBorins MylesBorins referenced this pull request Feb 27, 2018

Closed

v6.13.1 proposal #19025

@MylesBorins MylesBorins referenced this pull request Feb 27, 2018

Merged

v6.13.1 proposal #19027

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.