mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
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:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user