Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for local repo casing issue on Linux #1750

Merged
merged 7 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions src/code/LocalServerApiCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,29 +260,18 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu
string actualPkgName = packageName;

// this regex pattern matches packageName followed by a version (4 digit or 3 with prerelease word)
string regexPattern = $"{packageName}" + @".\d+\.\d+\.\d+(?:[a-zA-Z0-9-.]+|.\d)?.nupkg";
Regex rx = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
string regexPattern = $"{packageName}" + @"(\.\d+){1,3}(?:[a-zA-Z0-9-.]+|.\d)?\.nupkg";
_cmdletPassedIn.WriteDebug($"package file name pattern to be searched for is: {regexPattern}");

foreach (string path in Directory.GetFiles(Repository.Uri.LocalPath))
{
string packageFullName = Path.GetFileName(path);
MatchCollection matches = rx.Matches(packageFullName);
if (matches.Count == 0)
{
continue;
}

Match match = matches[0];

GroupCollection groups = match.Groups;
if (groups.Count == 0)
bool isMatch = Regex.IsMatch(packageFullName, regexPattern, RegexOptions.IgnoreCase);
if (!isMatch)
{
continue;
}

Capture group = groups[0];

NuGetVersion nugetVersion = GetInfoFromFileName(packageFullName: packageFullName, packageName: packageName, actualName: out actualPkgName, out errRecord);
_cmdletPassedIn.WriteDebug($"Version parsed as '{nugetVersion}'");

Expand Down Expand Up @@ -389,30 +378,19 @@ private FindResults FindVersionHelper(string packageName, string version, string

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

foreach (string path in Directory.GetFiles(Repository.Uri.LocalPath))
{
string packageFullName = Path.GetFileName(path);
MatchCollection matches = rx.Matches(packageFullName);
if (matches.Count == 0)
{
continue;
}

Match match = matches[0];

GroupCollection groups = match.Groups;
if (groups.Count == 0)
bool isMatch = Regex.IsMatch(packageFullName, regexPattern, RegexOptions.IgnoreCase);
if (!isMatch)
{
continue;
}

Capture group = groups[0];

NuGetVersion nugetVersion = GetInfoFromFileName(packageFullName: packageFullName, packageName: packageName, actualName: out actualPkgName, out errRecord);
_cmdletPassedIn.WriteDebug($"Version parsed as '{nugetVersion}'");

Expand All @@ -425,7 +403,7 @@ private FindResults FindVersionHelper(string packageName, string version, string
{
_cmdletPassedIn.WriteDebug("Found matching version");
string pkgFullName = $"{actualPkgName}.{nugetVersion.ToString()}.nupkg";
pkgPath = Path.Combine(Repository.Uri.LocalPath, pkgFullName);
pkgPath = path;
break;
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' {
$res.Version | Should -Be "1.0.0"
}

It "find resource given specific Name with incorrect casing and Version (should return correct casing)" {
# FindVersion()
$res = Find-PSResource -Name "test_local_mod3" -Version "1.0.0" -Repository $localRepo
$res.Name | Should -Be $testModuleName3
$res.Version | Should -Be "1.0.0"
}

It "find resource given specific Name, Version null (module) from a UNC-based local repository" {
# FindName()
$res = Find-PSResource -Name $testModuleName -Repository $localUNCRepo
Expand Down
Loading