Skip to content

Commit b4a7dab

Browse files
authored
Fix package name regex to account for 4 digit versions (#1739)
1 parent ceb1ce6 commit b4a7dab

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/code/LocalServerApiCalls.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ 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+(?:-\w+|.\d)*.nupkg";
263+
string regexPattern = $"{packageName}" + @".\d+\.\d+\.\d+(?:[a-zA-Z0-9-.]+|.\d)?.nupkg";
264264
Regex rx = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
265265
_cmdletPassedIn.WriteDebug($"package file name pattern to be searched for is: {regexPattern}");
266266

test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' {
1919
$commandName = "cmd1"
2020
$dscResourceName = "dsc1"
2121
$prereleaseLabel = ""
22+
$localNupkgRepo = "localNupkgRepo"
2223
Get-NewPSResourceRepositoryFile
2324
Register-LocalRepos
25+
Register-LocalTestNupkgsRepo
2426

2527
$localRepoUriAddress = Join-Path -Path $TestDrive -ChildPath "testdir"
2628
$tagsEscaped = @("'Test'", "'Tag2'", "'PSCommand_$cmdName'", "'PSDscResource_$dscName'")
@@ -319,4 +321,14 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' {
319321
$err.Count | Should -Not -Be 0
320322
$err[0].FullyQualifiedErrorId | Should -BeExactly "FindTagsPackageNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
321323
}
324+
325+
It "find package where prerelease label includes digits and period (i.e prerelease label is not just words)" {
326+
$nupkgName = "WebView2.Avalonia"
327+
$nupkgVersion = "1.0.1518.46"
328+
$prereleaseLabel = "preview.230207.17"
329+
$res = Find-PSResource -Name $nupkgName -Prerelease -Repository $localNupkgRepo
330+
$res.Name | Should -Be $nupkgName
331+
$res.Version | Should -Be $nupkgVersion
332+
$res.Prerelease | Should -Be $prereleaseLabel
333+
}
322334
}
Binary file not shown.

0 commit comments

Comments
 (0)