Normalize digit-only KB IDs to include KB prefix

Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-30 12:19:35 +00:00
parent ff54ca9015
commit dca2517cf0
2 changed files with 24 additions and 4 deletions

View File

@@ -94,8 +94,14 @@ namespace CustomActions
if (!KbPattern.IsMatch(trimmedKb))
return string.Empty;
// Return the sanitized value (uppercased for consistency)
return trimmedKb.ToUpperInvariant();
// Normalize to uppercase
var normalizedKb = trimmedKb.ToUpperInvariant();
// Ensure KB prefix is present (Win32_QuickFixEngineering always uses the KB prefix)
if (!normalizedKb.StartsWith("KB"))
normalizedKb = "KB" + normalizedKb;
return normalizedKb;
}
}
}

View File

@@ -46,10 +46,10 @@ namespace mRemoteNGTests.Installer
}
[Test]
public void SanitizeKbId_ValidNumberOnly_ReturnsUppercased()
public void SanitizeKbId_ValidNumberOnly_ReturnsWithKbPrefix()
{
var result = InvokeSanitizeKbId("1234567");
Assert.That(result, Is.EqualTo("1234567"));
Assert.That(result, Is.EqualTo("KB1234567"));
}
[Test]
@@ -175,6 +175,20 @@ namespace mRemoteNGTests.Installer
Assert.That(result, Is.EqualTo("HotFixID='KB1234567' OR HotFixID='KB7654321'"));
}
[Test]
public void BuildWhereClause_DigitOnlyKb_AddsKbPrefix()
{
var result = InvokeBuildWhereClause(new[] { "1234567" });
Assert.That(result, Is.EqualTo("HotFixID='KB1234567'"));
}
[Test]
public void BuildWhereClause_MixedPrefixedAndDigitOnly_NormalizesAll()
{
var result = InvokeBuildWhereClause(new[] { "1234567", "KB7654321", "kb9999999" });
Assert.That(result, Is.EqualTo("HotFixID='KB1234567' OR HotFixID='KB7654321' OR HotFixID='KB9999999'"));
}
#endregion
#region Helper Methods