From 4d9ff43e69a5ff9e5d5ac5f77af117a19bc7a8b3 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Mon, 11 Nov 2024 11:56:16 -0500 Subject: [PATCH 1/6] change casing of tests --- test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 b/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 index 1377cac2f..3791129df 100644 --- a/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 +++ b/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 @@ -12,7 +12,7 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' { BeforeAll{ $localRepo = "psgettestlocal" $localUNCRepo = 'psgettestlocal3' - $testModuleName = "test_local_mod" + $testModuleName = "test_Local_Mod" $testModuleName2 = "test_local_mod2" $testModuleName3 = "Test_Local_Mod3" $similarTestModuleName = "test_local_mod.similar" From efa018492bf6934682b9877ca401cf8927d5ac8a Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Tue, 12 Nov 2024 11:46:15 -0500 Subject: [PATCH 2/6] fix regex pattern for FindName scenario for local repos --- src/code/LocalServerApiCalls.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code/LocalServerApiCalls.cs b/src/code/LocalServerApiCalls.cs index 551a3fb3d..031dd5baf 100644 --- a/src/code/LocalServerApiCalls.cs +++ b/src/code/LocalServerApiCalls.cs @@ -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+(?:[a-zA-Z0-9-.]+|.\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}"); From 99a85888b398cffd865584a82001fc24bee513af Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Tue, 12 Nov 2024 17:24:24 -0500 Subject: [PATCH 3/6] fix path used by FindVersionHelper and add test --- src/code/LocalServerApiCalls.cs | 2 +- test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/code/LocalServerApiCalls.cs b/src/code/LocalServerApiCalls.cs index 031dd5baf..7f60efa03 100644 --- a/src/code/LocalServerApiCalls.cs +++ b/src/code/LocalServerApiCalls.cs @@ -425,7 +425,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; } } diff --git a/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 b/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 index 3791129df..52bf30b2c 100644 --- a/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 +++ b/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 @@ -12,7 +12,7 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' { BeforeAll{ $localRepo = "psgettestlocal" $localUNCRepo = 'psgettestlocal3' - $testModuleName = "test_Local_Mod" + $testModuleName = "test_local_mod" $testModuleName2 = "test_local_mod2" $testModuleName3 = "Test_Local_Mod3" $similarTestModuleName = "test_local_mod.similar" @@ -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)" { + # FindName() + $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 From 5b359caa71350beb35f0e75185a781f507094e90 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Tue, 12 Nov 2024 17:59:05 -0500 Subject: [PATCH 4/6] Update test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 --- test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 b/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 index 52bf30b2c..b89a245ee 100644 --- a/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 +++ b/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 @@ -61,7 +61,7 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' { } It "find resource given specific Name with incorrect casing and Version (should return correct casing)" { - # FindName() + # 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" From 197b6df57d8838ad8151f596604c442930fce2ae Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Wed, 20 Nov 2024 11:35:55 -0500 Subject: [PATCH 5/6] fix regex to account for 2 digit or 1 digit named .nupkgs --- src/code/LocalServerApiCalls.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code/LocalServerApiCalls.cs b/src/code/LocalServerApiCalls.cs index 7f60efa03..e03be71aa 100644 --- a/src/code/LocalServerApiCalls.cs +++ b/src/code/LocalServerApiCalls.cs @@ -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+(?:[a-zA-Z0-9-.]+|.\d)?.nupkg"; + string regexPattern = $"{packageName}" + @"(\.\d+){1,3}(?:[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}"); From 8e9e7896ffafc37a1fc7b82fb9aee7144e9ba3d0 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Tue, 3 Dec 2024 17:33:30 -0500 Subject: [PATCH 6/6] use IsMatch() instead of Matches() --- src/code/LocalServerApiCalls.cs | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src/code/LocalServerApiCalls.cs b/src/code/LocalServerApiCalls.cs index e03be71aa..324db1081 100644 --- a/src/code/LocalServerApiCalls.cs +++ b/src/code/LocalServerApiCalls.cs @@ -261,28 +261,17 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu // this regex pattern matches packageName followed by a version (4 digit or 3 with prerelease word) string regexPattern = $"{packageName}" + @"(\.\d+){1,3}(?:[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}"); 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}'"); @@ -389,7 +378,6 @@ 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; @@ -397,22 +385,12 @@ private FindResults FindVersionHelper(string packageName, string version, string 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}'");