@@ -260,29 +260,18 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu
260
260
string actualPkgName = packageName ;
261
261
262
262
// this regex pattern matches packageName followed by a version (4 digit or 3 with prerelease word)
263
- string regexPattern = $ "{ packageName } " + @".\d+\.\d+\.\d+(?:[a-zA-Z0-9-.]+|.\d)?.nupkg" ;
264
- Regex rx = new Regex ( regexPattern , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
263
+ string regexPattern = $ "{ packageName } " + @"(\.\d+){1,3}(?:[a-zA-Z0-9-.]+|.\d)?\.nupkg" ;
265
264
_cmdletPassedIn . WriteDebug ( $ "package file name pattern to be searched for is: { regexPattern } ") ;
266
265
267
266
foreach ( string path in Directory . GetFiles ( Repository . Uri . LocalPath ) )
268
267
{
269
268
string packageFullName = Path . GetFileName ( path ) ;
270
- MatchCollection matches = rx . Matches ( packageFullName ) ;
271
- if ( matches . Count == 0 )
272
- {
273
- continue ;
274
- }
275
-
276
- Match match = matches [ 0 ] ;
277
-
278
- GroupCollection groups = match . Groups ;
279
- if ( groups . Count == 0 )
269
+ bool isMatch = Regex . IsMatch ( packageFullName , regexPattern , RegexOptions . IgnoreCase ) ;
270
+ if ( ! isMatch )
280
271
{
281
272
continue ;
282
273
}
283
274
284
- Capture group = groups [ 0 ] ;
285
-
286
275
NuGetVersion nugetVersion = GetInfoFromFileName ( packageFullName : packageFullName , packageName : packageName , actualName : out actualPkgName , out errRecord ) ;
287
276
_cmdletPassedIn . WriteDebug ( $ "Version parsed as '{ nugetVersion } '") ;
288
277
@@ -389,30 +378,19 @@ private FindResults FindVersionHelper(string packageName, string version, string
389
378
390
379
// this regex pattern matches packageName followed by the requested version
391
380
string regexPattern = $ "{ packageName } .{ requiredVersion . ToNormalizedString ( ) } " + @".nupkg" ;
392
- Regex rx = new Regex ( regexPattern , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
393
381
_cmdletPassedIn . WriteDebug ( $ "pattern is: { regexPattern } ") ;
394
382
string pkgPath = String . Empty ;
395
383
string actualPkgName = String . Empty ;
396
384
397
385
foreach ( string path in Directory . GetFiles ( Repository . Uri . LocalPath ) )
398
386
{
399
387
string packageFullName = Path . GetFileName ( path ) ;
400
- MatchCollection matches = rx . Matches ( packageFullName ) ;
401
- if ( matches . Count == 0 )
402
- {
403
- continue ;
404
- }
405
-
406
- Match match = matches [ 0 ] ;
407
-
408
- GroupCollection groups = match . Groups ;
409
- if ( groups . Count == 0 )
388
+ bool isMatch = Regex . IsMatch ( packageFullName , regexPattern , RegexOptions . IgnoreCase ) ;
389
+ if ( ! isMatch )
410
390
{
411
391
continue ;
412
392
}
413
393
414
- Capture group = groups [ 0 ] ;
415
-
416
394
NuGetVersion nugetVersion = GetInfoFromFileName ( packageFullName : packageFullName , packageName : packageName , actualName : out actualPkgName , out errRecord ) ;
417
395
_cmdletPassedIn . WriteDebug ( $ "Version parsed as '{ nugetVersion } '") ;
418
396
@@ -425,7 +403,7 @@ private FindResults FindVersionHelper(string packageName, string version, string
425
403
{
426
404
_cmdletPassedIn . WriteDebug ( "Found matching version" ) ;
427
405
string pkgFullName = $ "{ actualPkgName } .{ nugetVersion . ToString ( ) } .nupkg";
428
- pkgPath = Path . Combine ( Repository . Uri . LocalPath , pkgFullName ) ;
406
+ pkgPath = path ;
429
407
break ;
430
408
}
431
409
}
0 commit comments