File tree 2 files changed +12
-2
lines changed
packages/angular_devkit/core/src/virtual-fs
2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -298,9 +298,11 @@ export type PosixPath = string & {
298
298
} ;
299
299
300
300
export function asWindowsPath ( path : Path ) : WindowsPath {
301
- const drive = path . match ( / ^ \/ ( \w ) \/ ( .* ) $ / ) ;
301
+ const drive = path . match ( / ^ \/ ( \w ) (?: \/ ( .* ) ) ? $ / ) ;
302
302
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 ;
304
306
}
305
307
306
308
return path . replace ( / \/ / g, '\\' ) as WindowsPath ;
Original file line number Diff line number Diff line change 8
8
import {
9
9
InvalidPathException ,
10
10
Path ,
11
+ asWindowsPath ,
11
12
basename ,
12
13
dirname ,
13
14
join ,
@@ -159,4 +160,11 @@ describe('path', () => {
159
160
expect ( basename ( normalize ( '.' ) ) ) . toBe ( '' ) ;
160
161
expect ( basename ( normalize ( './a/b/c' ) ) ) . toBe ( 'c' ) ;
161
162
} ) ;
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
+
162
170
} ) ;
You can’t perform that action at this time.
0 commit comments