Skip to content

Commit

Permalink
fix(@angular-devkit/core): handle drive only paths in windows
Browse files Browse the repository at this point in the history
When normalized path will not have a trailing slash, and at the moment the RegExp for drive needs to match `\c\`

Fixes #12670
  • Loading branch information
alan-agius4 authored and kyliau committed Nov 14, 2018
1 parent 1dbd574 commit a2aba28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/angular_devkit/core/src/virtual-fs/path.ts
Expand Up @@ -298,9 +298,11 @@ export type PosixPath = string & {
};

export function asWindowsPath(path: Path): WindowsPath {
const drive = path.match(/^\/(\w)\/(.*)$/);
const drive = path.match(/^\/(\w)(?:\/(.*))?$/);
if (drive) {
return `${drive[1]}:\\${drive[2].replace(/\//g, '\\')}` as WindowsPath;
const subPath = drive[2] ? drive[2].replace(/\//g, '\\') : '';

return `${drive[1]}:\\${subPath}` as WindowsPath;
}

return path.replace(/\//g, '\\') as WindowsPath;
Expand Down
8 changes: 8 additions & 0 deletions packages/angular_devkit/core/src/virtual-fs/path_spec.ts
Expand Up @@ -8,6 +8,7 @@
import {
InvalidPathException,
Path,
asWindowsPath,
basename,
dirname,
join,
Expand Down Expand Up @@ -159,4 +160,11 @@ describe('path', () => {
expect(basename(normalize('.'))).toBe('');
expect(basename(normalize('./a/b/c'))).toBe('c');
});

it('asWindowsPath', () => {
expect(asWindowsPath(normalize('c:/'))).toBe('c:\\');
expect(asWindowsPath(normalize('c:/b/'))).toBe('c:\\b');
expect(asWindowsPath(normalize('c:/b/c'))).toBe('c:\\b\\c');
});

});

0 comments on commit a2aba28

Please sign in to comment.