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); }