Skip to content

Commit 77b9487

Browse files
committed
Update device regex starting with relative path
paths starting with relative path to another drive for example `../../d:/some/dir/` are not resolved correctly. This regex update fixes it. Adding and updating tests along with the fix.
1 parent 616343b commit 77b9487

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

lib/path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function normalizeArray(parts, allowAboveRoot) {
5858
// Regex to split a windows path into three parts: [*, device, slash,
5959
// tail] windows-only
6060
var splitDeviceRe =
61-
/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
61+
/^(?:\.\.[\\\/]|\.[\\\/])*([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
6262

6363
// Regex to split the tail part of the above into [*, dir, basename, ext]
6464
var splitTailRe =

test/simple/test-path-parse-format.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ var winPaths = [
2828
'another_path\\DIR with spaces\\1\\2\\33\\index',
2929
'\\foo\\C:',
3030
'file',
31-
'.\\file',
3231

3332
// unc
3433
'\\\\server\\share\\file_path',

test/simple/test-path.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ if (isWindows) {
317317
[['c:/', '//dir'], 'c:\\dir'],
318318
[['c:/', '//server/share'], '\\\\server\\share\\'],
319319
[['c:/', '//server//share'], '\\\\server\\share\\'],
320-
[['c:/', '///some//dir'], 'c:\\some\\dir']
320+
[['c:/', '///some//dir'], 'c:\\some\\dir'],
321+
[['c:/some/random/path', '../../../../../d:/some/dir'], 'd:\\some\\dir']
321322
];
322323
} else {
323324
// Posix

0 commit comments

Comments
 (0)