-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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.relative() wrong result in v5.7.0 Windows #5447
Labels
Milestone
Comments
frickt
changed the title
path.relative() wrong result in v5.7.0 Windows 10
path.relative() wrong result in v5.7.0 Windows
Feb 26, 2016
targos
added
path
Issues and PRs related to the path subsystem.
confirmed-bug
Issues with confirmed bugs.
labels
Feb 26, 2016
right, sorry for my hastiness, confirmed that it's still borked with #5389 |
Played with it a bit, the following diff passes, but really not sure about it. diff --git a/lib/path.js b/lib/path.js
index d01e9b6..e012441 100644
--- a/lib/path.js
+++ b/lib/path.js
@@ -603,14 +603,28 @@ const win32 = {
var i = 0;
for (; i <= length; ++i) {
if (i === length) {
- if (lastCommonSep > 2 && // ignore separator match following device root
- toLen > length &&
- to.charCodeAt(i) === 92/*\*/) {
- // We get here if `from` is the exact base path for `to`.
- // For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
- return toOrig.slice(i + 1);
+ if (toLen > length) {
+ if (to.charCodeAt(toStart + i) === 92/*\*/) {
+ // We get here if `from` is the exact base path for `to`.
+ // For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
+ return toOrig.slice(toStart + i + 1);
+ } else if (lastCommonSep === 2) {
+ // We get here if `from` is the device root.
+ // For example: from='C:\\'; to='C:\\foo'
+ return toOrig.slice(toStart + i);
+ }
+ }
+ if (fromLen > length) {
+ if (from.charCodeAt(fromStart + i) === 92/*\*/) {
+ // We get here if `to` is the exact base path for `from`.
+ // For example: from:='C:\\foo\\bar'; to='C:\\foo'
+ lastCommonSep = i;
+ } else if (lastCommonSep === 2) {
+ // We get here if `to` is the device root.
+ // For example: from='C:\\foo\\bar'; to='C:\\'
+ lastCommonSep = 3;
+ }
}
- lastCommonSep = i;
break;
}
var fromCode = from.charCodeAt(fromStart + i);
diff --git a/test/parallel/test-path.js b/test/parallel/test-path.js
index aeb6ec0..02b280e 100644
--- a/test/parallel/test-path.js
+++ b/test/parallel/test-path.js
@@ -470,7 +470,9 @@ const relativeTests = [
['c:/AaAa/bbbb', 'c:/aaaa/bbbb', ''],
['c:/aaaaa/', 'c:/aaaa/cccc', '..\\aaaa\\cccc'],
['C:\\foo\\bar\\baz\\quux', 'C:\\', '..\\..\\..\\..'],
- ['C:\\foo\\test', 'C:\\foo\\test\\bar\\package.json', 'bar\\package.json']
+ ['C:\\foo\\test', 'C:\\foo\\test\\bar\\package.json', 'bar\\package.json'],
+ ['C:\\foo\\bar\\baz-quux', 'C:\\foo\\bar\\baz', '..\\baz'],
+ ['C:\\foo\\bar', 'C:\\baz\\quux', '..\\..\\baz\\quux']
]
],
[ path.posix.relative, |
@omsmith That LGTM, mind making a PR? |
@mscdex sure thing |
6 tasks
omsmith
added a commit
to omsmith/node
that referenced
this issue
Feb 27, 2016
when the basename of "to" was a prefix of the basename of "from" win32 relative() would miss including it in the result Fixes nodejs#5447
omsmith
added a commit
to omsmith/node
that referenced
this issue
Feb 27, 2016
adds posix test cases for paths similar to those that caused nodejs#5447
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Version: <= 5.6.0:
Version: 5.7.0
'..' needs to be '..\bootstrap'
The text was updated successfully, but these errors were encountered: