Skip to content

Commit

Permalink
Fix package name regex to account for 4 digit versions (#1739)
Browse files Browse the repository at this point in the history
  • Loading branch information
anamnavi authored Oct 30, 2024
1 parent ceb1ce6 commit b4a7dab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/code/LocalServerApiCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ 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+(?:-\w+|.\d)*.nupkg";
string regexPattern = $"{packageName}" + @".\d+\.\d+\.\d+(?:[a-zA-Z0-9-.]+|.\d)?.nupkg";
Regex rx = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
_cmdletPassedIn.WriteDebug($"package file name pattern to be searched for is: {regexPattern}");

Expand Down
12 changes: 12 additions & 0 deletions test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' {
$commandName = "cmd1"
$dscResourceName = "dsc1"
$prereleaseLabel = ""
$localNupkgRepo = "localNupkgRepo"
Get-NewPSResourceRepositoryFile
Register-LocalRepos
Register-LocalTestNupkgsRepo

$localRepoUriAddress = Join-Path -Path $TestDrive -ChildPath "testdir"
$tagsEscaped = @("'Test'", "'Tag2'", "'PSCommand_$cmdName'", "'PSDscResource_$dscName'")
Expand Down Expand Up @@ -319,4 +321,14 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' {
$err.Count | Should -Not -Be 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "FindTagsPackageNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
}

It "find package where prerelease label includes digits and period (i.e prerelease label is not just words)" {
$nupkgName = "WebView2.Avalonia"
$nupkgVersion = "1.0.1518.46"
$prereleaseLabel = "preview.230207.17"
$res = Find-PSResource -Name $nupkgName -Prerelease -Repository $localNupkgRepo
$res.Name | Should -Be $nupkgName
$res.Version | Should -Be $nupkgVersion
$res.Prerelease | Should -Be $prereleaseLabel
}
}
Binary file not shown.

0 comments on commit b4a7dab

Please sign in to comment.