Skip to content

Commit 2ec92f2

Browse files
authored
Bugfix for local repo casing issue on Linux (#1750)
1 parent 232ae94 commit 2ec92f2

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

src/code/LocalServerApiCalls.cs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -260,29 +260,18 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu
260260
string actualPkgName = packageName;
261261

262262
// 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";
265264
_cmdletPassedIn.WriteDebug($"package file name pattern to be searched for is: {regexPattern}");
266265

267266
foreach (string path in Directory.GetFiles(Repository.Uri.LocalPath))
268267
{
269268
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)
280271
{
281272
continue;
282273
}
283274

284-
Capture group = groups[0];
285-
286275
NuGetVersion nugetVersion = GetInfoFromFileName(packageFullName: packageFullName, packageName: packageName, actualName: out actualPkgName, out errRecord);
287276
_cmdletPassedIn.WriteDebug($"Version parsed as '{nugetVersion}'");
288277

@@ -389,30 +378,19 @@ private FindResults FindVersionHelper(string packageName, string version, string
389378

390379
// this regex pattern matches packageName followed by the requested version
391380
string regexPattern = $"{packageName}.{requiredVersion.ToNormalizedString()}" + @".nupkg";
392-
Regex rx = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
393381
_cmdletPassedIn.WriteDebug($"pattern is: {regexPattern}");
394382
string pkgPath = String.Empty;
395383
string actualPkgName = String.Empty;
396384

397385
foreach (string path in Directory.GetFiles(Repository.Uri.LocalPath))
398386
{
399387
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)
410390
{
411391
continue;
412392
}
413393

414-
Capture group = groups[0];
415-
416394
NuGetVersion nugetVersion = GetInfoFromFileName(packageFullName: packageFullName, packageName: packageName, actualName: out actualPkgName, out errRecord);
417395
_cmdletPassedIn.WriteDebug($"Version parsed as '{nugetVersion}'");
418396

@@ -425,7 +403,7 @@ private FindResults FindVersionHelper(string packageName, string version, string
425403
{
426404
_cmdletPassedIn.WriteDebug("Found matching version");
427405
string pkgFullName = $"{actualPkgName}.{nugetVersion.ToString()}.nupkg";
428-
pkgPath = Path.Combine(Repository.Uri.LocalPath, pkgFullName);
406+
pkgPath = path;
429407
break;
430408
}
431409
}

test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' {
6060
$res.Version | Should -Be "1.0.0"
6161
}
6262

63+
It "find resource given specific Name with incorrect casing and Version (should return correct casing)" {
64+
# FindVersion()
65+
$res = Find-PSResource -Name "test_local_mod3" -Version "1.0.0" -Repository $localRepo
66+
$res.Name | Should -Be $testModuleName3
67+
$res.Version | Should -Be "1.0.0"
68+
}
69+
6370
It "find resource given specific Name, Version null (module) from a UNC-based local repository" {
6471
# FindName()
6572
$res = Find-PSResource -Name $testModuleName -Repository $localUNCRepo

0 commit comments

Comments
 (0)