Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b33879d

Browse filesBrowse files
omsmithsilverwind
authored andcommitted
path: fix win32 relative() when "to" is a prefix
when the basename of "to" was a prefix of the basename of "from" win32 relative() would miss including it in the result Fixes: #5447 PR-URL: #5456 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Roman Reiss <me@silverwind.io>
1 parent 8b16ba3 commit b33879d
Copy full SHA for b33879d

File tree

Expand file treeCollapse file tree

2 files changed

+23
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-8
lines changed
Open diff view settings
Collapse file

‎lib/path.js‎

Copy file name to clipboardExpand all lines: lib/path.js
+21-7Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,14 +603,28 @@ const win32 = {
603603
var i = 0;
604604
for (; i <= length; ++i) {
605605
if (i === length) {
606-
if (lastCommonSep > 2 && // ignore separator match following device root
607-
toLen > length &&
608-
to.charCodeAt(i) === 92/*\*/) {
609-
// We get here if `from` is the exact base path for `to`.
610-
// For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
611-
return toOrig.slice(i + 1);
606+
if (toLen > length) {
607+
if (to.charCodeAt(toStart + i) === 92/*\*/) {
608+
// We get here if `from` is the exact base path for `to`.
609+
// For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
610+
return toOrig.slice(toStart + i + 1);
611+
} else if (lastCommonSep === 2) {
612+
// We get here if `from` is the device root.
613+
// For example: from='C:\\'; to='C:\\foo'
614+
return toOrig.slice(toStart + i);
615+
}
616+
}
617+
if (fromLen > length) {
618+
if (from.charCodeAt(fromStart + i) === 92/*\*/) {
619+
// We get here if `to` is the exact base path for `from`.
620+
// For example: from='C:\\foo\\bar'; to='C:\\foo'
621+
lastCommonSep = i;
622+
} else if (lastCommonSep === 2) {
623+
// We get here if `to` is the device root.
624+
// For example: from='C:\\foo\\bar'; to='C:\\'
625+
lastCommonSep = 3;
626+
}
612627
}
613-
lastCommonSep = i;
614628
break;
615629
}
616630
var fromCode = from.charCodeAt(fromStart + i);
Collapse file

‎test/parallel/test-path.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-path.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ const relativeTests = [
470470
['c:/AaAa/bbbb', 'c:/aaaa/bbbb', ''],
471471
['c:/aaaaa/', 'c:/aaaa/cccc', '..\\aaaa\\cccc'],
472472
['C:\\foo\\bar\\baz\\quux', 'C:\\', '..\\..\\..\\..'],
473-
['C:\\foo\\test', 'C:\\foo\\test\\bar\\package.json', 'bar\\package.json']
473+
['C:\\foo\\test', 'C:\\foo\\test\\bar\\package.json', 'bar\\package.json'],
474+
['C:\\foo\\bar\\baz-quux', 'C:\\foo\\bar\\baz', '..\\baz']
474475
]
475476
],
476477
[ path.posix.relative,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.