@@ -120,6 +120,9 @@ export interface Uri {
120120 toJsonObj ( ) : any ;
121121}
122122
123+ const _dosPathRegex = / ^ \/ [ a - z A - Z ] : \/ / ;
124+ const _win32NormalizationRegex = / \/ / g;
125+
123126// Returns just the fsPath path portion of a vscode URI.
124127function getFilePath ( uri : URI ) : string {
125128 let filePath : string | undefined ;
@@ -136,14 +139,14 @@ function getFilePath(uri: URI): string {
136139
137140 // If this is a DOS-style path with a drive letter, remove
138141 // the leading slash.
139- if ( filePath . match ( / ^ \/ [ a - z A - Z ] : \/ / ) ) {
142+ if ( filePath . match ( _dosPathRegex ) ) {
140143 filePath = filePath . slice ( 1 ) ;
141144 }
142145
143146 // vscode.URI normalizes the path to use the correct path separators.
144147 // We need to do the same.
145148 if ( process ?. platform === 'win32' ) {
146- filePath = filePath . replace ( / \/ / g , '\\' ) ;
149+ filePath = filePath . replace ( _win32NormalizationRegex , '\\' ) ;
147150 }
148151
149152 return filePath ;
@@ -164,16 +167,16 @@ function normalizeUri(uri: string | URI): { uri: URI; str: string } {
164167 return { uri : finalURI , str : finalString } ;
165168}
166169
170+ const windowsUriRegEx = / ^ [ a - z A - Z ] : \\ ? / ;
171+ const uriRegEx = / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 + . - ] * : \/ ? \/ ? / ;
172+
167173export namespace Uri {
168174 export interface IServiceProvider {
169175 get < T > ( key : ServiceKey < T > ) : T ;
170176 }
171177
172178 export function maybeUri ( value : string ) {
173- const windows = / ^ [ a - z A - Z ] : \\ ? / ;
174- const uri = / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 + . - ] * : \/ ? \/ ? / ;
175-
176- return uri . test ( value ) && ! windows . test ( value ) ;
179+ return uriRegEx . test ( value ) && ! windowsUriRegEx . test ( value ) ;
177180 }
178181
179182 export function create ( value : string , serviceProvider : IServiceProvider , checkRelative ?: boolean ) : Uri ;
0 commit comments