Address code review feedback - optimize regex and use Array.Empty

Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-30 12:16:52 +00:00
parent c683854678
commit 76cb0a1e0b
2 changed files with 3 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ namespace CustomActions
public class InstalledWindowsUpdateChecker
{
private readonly ManagementScope _managementScope;
private static readonly Regex KbPattern = new Regex(@"^(KB)?\d+$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
public InstalledWindowsUpdateChecker()
{
@@ -88,12 +89,9 @@ namespace CustomActions
// KB IDs should match the pattern: KB followed by digits (e.g., KB1234567)
// or just digits (e.g., 1234567)
// This regex allows optional "KB" prefix followed by one or more digits
var kbPattern = new Regex(@"^(KB)?\d+$", RegexOptions.IgnoreCase);
// Trim whitespace and check if it matches the expected pattern
var trimmedKb = kbId.Trim();
if (!kbPattern.IsMatch(trimmedKb))
if (!KbPattern.IsMatch(trimmedKb))
return string.Empty;
// Return the sanitized value (uppercased for consistency)

View File

@@ -157,7 +157,7 @@ namespace mRemoteNGTests.Installer
[Test]
public void BuildWhereClause_EmptyList_ReturnsEmpty()
{
var result = InvokeBuildWhereClause(new string[0]);
var result = InvokeBuildWhereClause(Array.Empty<string>());
Assert.That(result, Is.Empty);
}