From 76cb0a1e0bcd78236909007e07437bcb083300e9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Dec 2025 12:16:52 +0000 Subject: [PATCH] Address code review feedback - optimize regex and use Array.Empty Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com> --- .../CustomActions/InstalledWindowsUpdateChecker.cs | 6 ++---- .../Installer/InstalledWindowsUpdateCheckerTests.cs | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/mRemoteNGInstaller/CustomActions/InstalledWindowsUpdateChecker.cs b/mRemoteNGInstaller/CustomActions/InstalledWindowsUpdateChecker.cs index 070cbb334..3be331bcf 100644 --- a/mRemoteNGInstaller/CustomActions/InstalledWindowsUpdateChecker.cs +++ b/mRemoteNGInstaller/CustomActions/InstalledWindowsUpdateChecker.cs @@ -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) diff --git a/mRemoteNGTests/Installer/InstalledWindowsUpdateCheckerTests.cs b/mRemoteNGTests/Installer/InstalledWindowsUpdateCheckerTests.cs index f45cc0a61..aa47bc791 100644 --- a/mRemoteNGTests/Installer/InstalledWindowsUpdateCheckerTests.cs +++ b/mRemoteNGTests/Installer/InstalledWindowsUpdateCheckerTests.cs @@ -157,7 +157,7 @@ namespace mRemoteNGTests.Installer [Test] public void BuildWhereClause_EmptyList_ReturnsEmpty() { - var result = InvokeBuildWhereClause(new string[0]); + var result = InvokeBuildWhereClause(Array.Empty()); Assert.That(result, Is.Empty); }