Skip to content

Commit a2aba28

Browse files
alan-agius4Keen Yee Liau
authored and
Keen Yee Liau
committed
fix(@angular-devkit/core): handle drive only paths in windows
When normalized path will not have a trailing slash, and at the moment the RegExp for drive needs to match `\c\` Fixes #12670
1 parent 1dbd574 commit a2aba28

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/angular_devkit/core/src/virtual-fs/path.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,11 @@ export type PosixPath = string & {
298298
};
299299

300300
export function asWindowsPath(path: Path): WindowsPath {
301-
const drive = path.match(/^\/(\w)\/(.*)$/);
301+
const drive = path.match(/^\/(\w)(?:\/(.*))?$/);
302302
if (drive) {
303-
return `${drive[1]}:\\${drive[2].replace(/\//g, '\\')}` as WindowsPath;
303+
const subPath = drive[2] ? drive[2].replace(/\//g, '\\') : '';
304+
305+
return `${drive[1]}:\\${subPath}` as WindowsPath;
304306
}
305307

306308
return path.replace(/\//g, '\\') as WindowsPath;

packages/angular_devkit/core/src/virtual-fs/path_spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import {
99
InvalidPathException,
1010
Path,
11+
asWindowsPath,
1112
basename,
1213
dirname,
1314
join,
@@ -159,4 +160,11 @@ describe('path', () => {
159160
expect(basename(normalize('.'))).toBe('');
160161
expect(basename(normalize('./a/b/c'))).toBe('c');
161162
});
163+
164+
it('asWindowsPath', () => {
165+
expect(asWindowsPath(normalize('c:/'))).toBe('c:\\');
166+
expect(asWindowsPath(normalize('c:/b/'))).toBe('c:\\b');
167+
expect(asWindowsPath(normalize('c:/b/c'))).toBe('c:\\b\\c');
168+
});
169+
162170
});

0 commit comments

Comments
 (0)